QGraphicsItem layouts
-
Unfortunately I can't see any documented information about this.
I need a layout class likeQLayoutbut not for widgets in widgets but forQGraphicsIteminsideQGraphicsItems. I have:class AnotherGraphicsItem : public QGraphicsItem { public: QRectF boundingRect(); void paint(QPainter *painter, ...) { painter->drawRect(0, 0, 30, 30); // ... } }; class GraphicsItem : public QGraphicsItem { public: QRectF boundingRect(); void paint(...) { for (size_t i = 0; i < 4; ++i) { AnotherGraphicsItem *aItem = new AnotherGraphicsItem(); aItem->setPos(i * 20, 0); aItem->setParent(this); } } }; class GraphicsView : public QGraphicsView { public: GraphicsView(){ setScene(new QGraphicsScene(this)); populate(); } void populate() { QGraphicsItem *item = new GraphicsItem(); scene()->addItem(item); } };Briefly, my
GraphicsViewobjects have a scene which has QGraphicsItem objects inside another QGraphicsItem objectsQGraphicsView -> QGraphicsScene -> QGraphicsItem (GraphicsItem) -> 4x QGraphicsItem (AnotherGraphicsItem)
The problem is that I need
AnotherGraphicsItemto be aligned somehow in the outerGraphicsItemobject. I've though to useQGraphicsLayoutbut it seems it needs to be used insideQGraphicsWidgetwhich I am not gonna use or it works only inQGraphicsView(it hassetLayout()method).Some good examples are also welcome.
-
You can use QGraphicsLayout classes. These classes require some information about the items they lay out, which is in QGraphicsLayoutItem.
The simple option is to inherit from QGraphicsWidget (which inherits from QGraphicsLayoutItem), set size policies, fixed/preferred sizes, etc.
If you don't like to do that for some reason (I don't see any, frankly), you can inherit from QGraphicsLayoutItem directly.