January 2016
Beginner
512 pages
12h 35m
English
As a first approach, let's create an item that paints a black rectangle:
class BlackRectangle : public QGraphicsItem {
public:
explicit BlackRectangle(QGraphicsItem *parent = 0)
: QGraphicsItem(parent) {}
virtual ~BlackRectangle() {}
QRectF boundingRect() const {
return QRectF(0, 0, 75, 25);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option)
Q_UNUSED(widget)
painter->fillRect(boundingRect(), Qt::black);
}
};First, we subclass QGraphicItem and call the new class BlackRectangle. The class' constructor accepts a pointer to a QGraphicItem item. This pointer is then passed to the constructor of the QGraphicItem item. We ...