Time for action – creating an item where transformations can easily be seen
First we set up a playground. To do this, we subclass a QGraphicsRectItem
item and customize its paint function as follows:
void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) const QPen oldPen = painter->pen(); const QRectF r = rect(); const QColor fillColor = Qt::red; const qreal square = r.width() / 10.0; painter->fillRect(QRectF(0, 0, square, square), fillColor); painter->fillRect(QRectF(r.width() - square, 0, square, square), fillColor); painter->fillRect(QRectF(0,r.height() - square, square, square), fillColor); painter->fillRect(QRectF(r.width() - square, r.height() - square,square, ...
Get Game Programming Using Qt now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.