不幸的是,我看不到任何有关此的记录信息。我需要一个布局类,QLayout但不是用于小部件中的小部件,而是用于QGraphicsItem内部QGraphicsItems。我有:
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);
}
};
简而言之,我的GraphicsView对象有一个场景,该场景在另一个 QGraphicsItem 对象中包含 QGraphicsItem 对象
QGraphicsView -> QGraphicsScene -> QGraphicsItem (GraphicsItem) -> 4x QGraphicsItem (AnotherGraphicsItem)
问题是我需要AnotherGraphicsItem在外部GraphicsItem对象中以某种方式对齐。我虽然使用过,QGraphicsLayout但似乎它需要在QGraphicsWidget我不会使用的内部使用,或者它仅适用于QGraphicsView(它有setLayout()方法)。
也欢迎一些好的例子。