QLayout: Attempting to add QLayout "" to MainWindow "", which already has a layout [SOLVED]
-
I'm trying to insert a layout and I got this:
QLayout: Attempting to add QLayout "" to MainWindow "", which already has a layout
#include "mainwindow.hpp" #include <QVBoxLayout> #include <QHBoxLayout> #include <QLineEdit> #include <QPushButton> #include <QProgressBar> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { auto layout = new QVBoxLayout(this); auto vlayout = new QVBoxLayout(); auto hlayout = new QHBoxLayout(); auto edit = new QLineEdit(this); auto push = new QPushButton(this); push->setText("Go!"); hlayout->addWidget(edit); hlayout->addWidget(push); vlayout->addLayout(hlayout); auto progress = new QProgressBar(this); vlayout->addWidget(progress); layout->addLayout(vlayout); setTabOrder(edit, push); }
-
Hi,
You can't, QMainWindow already has a special layout that handles everything in it (docks, menus, toolbars etc.) You have to put your layout on a widget that you will set on your QMainWindow through setCentralWidget
-
Yes, it is right indeed