April 2018
Beginner
714 pages
18h 21m
English
Let's add a number to each of the corner circles:
child->setPos(pos);
QGraphicsSimpleTextItem *text =
new QGraphicsSimpleTextItem(QString::number(i), child);
text->setBrush(Qt::green);
text->setPos(-text->boundingRect().width() / 2,
-text->boundingRect().height() / 2);
The QString::number(i) function returns the string representation of number i. The text item is a child of the circle item, so its position is relative to the circle's origin point (in our case, its center). As we saw earlier, the text is displayed to the top-left of the item's origin, so if we want to center the text within the circle, we need to shift it up and right by half of the item's size. Now the text is positioned ...
Read now
Unlock full access