Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > С/С++: Кроссплатформенное программирование, Qt/Gtk+/wxWidgets > shape из двух прямоугольников


Автор: math64 18.2.2013, 14:58
Для своего GraphicsItem нужно вычислить shape.
Код

QPainterPath GraphicsItem::shape() const {
       QPainterPath path;
       path.addPath(getPath1() );
       path.addPath(getPath2() );
       return path;
}
QPainterPath GraphicsItem::getPath1() const {
       QPainterPath path;
       path.addRect(QRect(0,0,100,100) );
       return path;
}
QPainterPath GraphicsItem::getPath2() const {
       QPainterPath path;
       path.addRect(QRect(10,10,80,80) );
       return path;
}

В результате получается, что второй прямоугольник не добавляется, а вычитается.
Как правильно добавить путь, чтобы этого не было?

Добавлено @ 15:04
Вот так работает:
Код

QPainterPath GraphicsItem::shape() const {
       QPainterPath path;
       path.setFillRule(Qt::WindingFill);
       path.addPath(getPath1() );
       path.addPath(getPath2() );
       return path;
}
QPainterPath GraphicsItem::getPath1() const {
       QPainterPath path;
       path.setFillRule(Qt::WindingFill);
       path.addRect(QRect(0,0,100,100) );
       return path;
}
QPainterPath GraphicsItem::getPath2() const {
       QPainterPath path;
       path.setFillRule(Qt::WindingFill);
       path.addRect(QRect(10,10,80,80) );
       return path;
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)