how to add qgraphicscene/view to qwidget
-
how do i add qgraphicscene/view to qwidget
for example, this create a separate window than wdiget.
scene and view are qgraphicscene and qgraphicview declare in mytest_widget class
mytest_widget::mytest_widget(QWidget *parent) : QWidget(parent)
{
rect = new QGraphicsRectItem();scene.addItem(rect);
view.setScene(scene);
view.show();
} -
Hi,
Take a look at the Layout Management chapter in Qt's documentation.
-
thx, i look at it, but it didn't mention qgraphscene. i add QHBoxLayout etc before with button etc, but not sure about qgraphicscene?
something like this
mytest_widget::mytest_widget(QWidget *parent) : QWidget(parent)
{
mytest_widget_dis *display = new mytest_widget_dis();
display->view->show();
QVBoxLayout *mainLayout = new QVBoxLayout;mainLayout->addWidget( display );
}
mytest_widget_dis::mytest_widget_dis(QWidget *parent)
{
rect = new QGraphicsRectItem();
rect->setRect(0,0,100,100);
rect->setBrush(Qt::black);
pen.setColor(Qt::green);
rect->setPen(pen);
scene = new QGraphicsScene(this);
scene->addItem(rect);view=new QGraphicsView(scene);
}
thought Scene still show a separated GUI from main widget
-
You are not setting your layout on the widget.