2
QGraphicsScene
과 함께 작동하여 QGraphicsItem
의 그룹이 장면에 선형으로 배치되도록 노력하는 중, 을 처리하는 데 어려움을 겪고 있습니다. 나는 아래의 방법을 사용하여 시도했다 : 모든 항목이 여전히 서로의 상단에 배치로 대신,QGraphicsLinearLayout을 QGraphicsScene과 함께 올바르게 사용하여 QGraphicsItem을 배치하는 방법은 무엇입니까?
#include <QApplication>
#include <QBrush>
#include <QGraphicsItem>
#include <QGraphicsLayoutItem>
#include <QGraphicsLinearLayout>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include <QPen>
class MyShape : public QGraphicsRectItem, public QGraphicsLayoutItem {
public:
MyShape(void) {
setPen(QPen(QBrush(Qt::black), 1));
setBrush(QBrush(Qt::green));
setRect(0, 0, 20, 20);
}
virtual QSizeF sizeHint(Qt::SizeHint which,
const QSizeF& constraint = QSizeF()) const {
Q_UNUSED(which);
Q_UNUSED(constraint);
return boundingRect().size();
}
};
int main(int argc, char** argv) {
QApplication app(argc, argv);
QGraphicsScene scene;
MyShape* shape1 = new MyShape;
MyShape* shape2 = new MyShape;
MyShape* shape3 = new MyShape;
scene.addItem(shape1);
scene.addItem(shape2);
scene.addItem(shape3);
QGraphicsLinearLayout* layout = new QGraphicsLinearLayout;
layout->addItem(shape1);
layout->addItem(shape2);
layout->addItem(shape3);
QGraphicsWidget* container = new QGraphicsWidget;
container->setLayout(layout);
scene.addItem(container);
QGraphicsView view;
view.setScene(&scene);
view.show();
return app.exec();
}
이 작동하지 않는 선형 레이아웃에 의해 결정 레이아웃에 따라 (서로 옆에). 내가 도대체 뭘 잘못하고있는 겁니까?