Reputation: 1725
I would like to add a QGraphicsView(a sub class of it called Menu) inside a QMainWindow programmatically (using code).
In fact I already do that but the problem is the embedded QGraphicsView is not showed.
Here is the code I used inside QMainWindow::init()
menuView=new Menu(this);
menuView->show();
I already create the scene and insert items inside the Menu class.
What's wrong?
Upvotes: 0
Views: 4550
Reputation: 25165
When using QMainWindow, use setCentralWidget:
int main( int argc, char** argv ) {
QApplication app( argc, argv );
...
QMainWindow mw;
Menu menu;
mw.setCentralWidget( &menu );
mw.show();
return app.exec();
}
Upvotes: 2
Reputation: 6181
try
menuView=new Menu(this);
menuView->show();
QLayout* layout=new QVBoxLayout();
layout->addWidget(menuView);
this->setLayout(layout);
if you are not using layouts, or
menuView=new Menu(this);
menuView->show();
QLayout* layout=this->layout();
layout->addWidget(menuView);
this->setLayout(layout);
if your form already have a layout.
Upvotes: 2