The essence of the problem is that it is not clear how one can unite several derivatives of QGraphicItem objects into units. The object on which the operations will be applied is the same as for the derived class?
- Look towards QGraphicsItemGroup - gil9red
- Already tried, but to no avail. Need an example. As Linus Torvalds used to say: "Chatter is worth nothing, show us the code." - Max
- 3Then, it was necessary to attach your attempts to the question, or Linus Torvalds said: “Chatter is worthless, show us the code” :) - gil9red
|
1 answer
A yellow square is created on the stage, on which two inscriptions are located, and this square can be moved:
class MyGroupItem: public QGraphicsItemGroup { public: MyGroupItem() : QGraphicsItemGroup() { setFlags(QGraphicsItem::ItemIsMovable); text.setPlainText("!!!"); text2.setPlainText("@@@"); text2.setPos(0, 20); rect.setRect(0, 0, 40, 40); rect.setBrush(Qt::yellow); addToGroup(&rect); addToGroup(&text); addToGroup(&text2); } private: QGraphicsTextItem text; QGraphicsTextItem text2; QGraphicsRectItem rect; };
|