Taken directly from the Qt 4.5.2 documentation, in the Detailed Description of QGraphicsGridLayout:
QGraphicsWidget
*textEdit
= scene.
addWidget(new QTextEdit);
QGraphicsWidget
*pushButton
= scene.
addWidget(new QPushButton);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit, 0, 0);
layout->addItem(pushButton, 0, 1);
QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(layout);
scene.addItem(form);
QGraphicsScene scene;
QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
layout->addItem(textEdit, 0, 0);
layout->addItem(pushButton, 0, 1);
QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(layout);
scene.addItem(form);
To copy to clipboard, switch view to plain text mode
First problem: I don't see anything if I wrap this in a simple QApplication:
int main()
{
//the above code, with the first line:
//QGraphicsScene scene(widget);
widget->show();
return app.exec();
}
int main()
{
QApplication app();
QWidget *widget;
//the above code, with the first line:
//QGraphicsScene scene(widget);
widget->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
This structure is really important, but when I try to implement it in my class's constructor, it won't compile. What's wrong here? Thanks!
Bookmarks