I am trying to set my layout (using setLayout()
) in my mainwindow. It does not show anything on launch:
class MainWindow : public QMainWindow
{
You need to change the last two lines of code to be the following:
QWidget *widget = new QWidget();
widget->setLayout(VBoxLayout);
setCentralWidget(widget);
//VBoxLayout->addWidget(new QLayout);
//setLayout(VBoxLayout);
The QMainWindow
is a special case. You set the contents of this widget by putting the layout in a new QWidget
and then setting that as the central widget.
See this answer also.