QLayout: attempting to add QLayout "" to MainWindow, which already has a layout (solved)
-
wrote on 13 Apr 2015, 09:30 last edited by houmingc
In Mainwindow, i create below code.
when run, i get QLayout: attempting to add QLayout "" to MainWindow, which already has a layout. How to remedy?
i could w.setCentralWidget (centralWidget) in Main but not MainWindow.cppLayout_page1= new QVBoxLayout(); Layout_page1->addLayout(topLayout); Layout_page1->addWidget(ml); w_page1 = new QWidget; stackedLayout = new QStackedLayout; stackedLayout->addWidget(w_page1);
-
In Mainwindow, i create below code.
when run, i get QLayout: attempting to add QLayout "" to MainWindow, which already has a layout. How to remedy?
i could w.setCentralWidget (centralWidget) in Main but not MainWindow.cppLayout_page1= new QVBoxLayout(); Layout_page1->addLayout(topLayout); Layout_page1->addWidget(ml); w_page1 = new QWidget; stackedLayout = new QStackedLayout; stackedLayout->addWidget(w_page1);
-
Hi,
If MainWindow is a QMainWindow and you build centralWidget in MainWindow just call
setCentralWidget(centralWidget);
You can't set a layout on a QMainWindow because it already has one that makes all the work for dock widgets etc.
-
Hi,
If MainWindow is a QMainWindow and you build centralWidget in MainWindow just call
setCentralWidget(centralWidget);
You can't set a layout on a QMainWindow because it already has one that makes all the work for dock widgets etc.
wrote on 14 Apr 2015, 13:51 last edited byIn mainWindow, i have to transverse between 5 pages using a timer.
QWidget do not have method setCentralWidget();QWidget* w_page1; QWidget* w_page2; QWidget* w_page3; QWidget* w_page4; QWidget* w_page5; w_page1->setLayout(Layout_page1); w_page1->showMaximized(); w_page1->setStyleSheet("background-color:black"); w_page2->setLayout(Layout_page2); w_page2->showMaximized(); w_page2->setStyleSheet("background-color:black"); w_page3->setLayout(Layout_page3); w_page3->showMaximized(); w_page3->setStyleSheet("background-color:white"); w_page4->setLayout(Layout_page4); w_page4->showMaximized(); w_page4->setStyleSheet("background-color:white"); w_page5->setLayout(Layout_page5); w_page5->showMaximized(); w_page5->setStyleSheet("background-color:white");
-
In mainWindow, i have to transverse between 5 pages using a timer.
QWidget do not have method setCentralWidget();QWidget* w_page1; QWidget* w_page2; QWidget* w_page3; QWidget* w_page4; QWidget* w_page5; w_page1->setLayout(Layout_page1); w_page1->showMaximized(); w_page1->setStyleSheet("background-color:black"); w_page2->setLayout(Layout_page2); w_page2->showMaximized(); w_page2->setStyleSheet("background-color:black"); w_page3->setLayout(Layout_page3); w_page3->showMaximized(); w_page3->setStyleSheet("background-color:white"); w_page4->setLayout(Layout_page4); w_page4->showMaximized(); w_page4->setStyleSheet("background-color:white"); w_page5->setLayout(Layout_page5); w_page5->showMaximized(); w_page5->setStyleSheet("background-color:white");
wrote on 14 Apr 2015, 13:55 last edited byLayout_page3 = new QHBoxLayout(this);
Layout_page3->addWidget(w);
Layout_page3->addLayout(rightLayout2);
this->setCentralWidget(Layout_page3);Error
No matching function for call to
MainWindow::setCentralWidget(QHBoxLayout*) -
wrote on 14 Apr 2015, 15:29 last edited by
-
setCentralWidget as the name implies needs a QWidget not a QHBoxLayout.
Put your Layout_page3 on a placeholder widget and then set it as central widget -
setCentralWidget as the name implies needs a QWidget not a QHBoxLayout.
Put your Layout_page3 on a placeholder widget and then set it as central widgetwrote on 15 Apr 2015, 15:27 last edited byLayout_page3 = new QHBoxLayout(this);
Layout_page3->addWidget(w);
Layout_page3->addLayout(rightLayout2);
setCentralWidget(Layout_page3);This doesn't work, neither is this
this->setCentralWidget(Layout_page3); -
Again: setCentralWidget takes a QWidget not a QLayout as a parameter.
Again 2:Put your Layout_page3 layout on a QWidget and then set that widget using setCentralWidget.
QWidget *placeholderWidget = new QWidget; placeholderWidget->setLayout(Layout_page3); setCentralWidget(placeholderWidget);
-
wrote on 15 Apr 2015, 15:58 last edited by
git push my code. Thanks, although i got no error, but the warning is still there.
-
Are you still trying to set a layout on your main window ?
-
wrote on 17 Apr 2015, 00:51 last edited by houmingc
-
So again: you can not do that as the error message says. As already stated: QMainWindow already has a layout. The one that handles dock widgets, menu bar, status bar etc. You can't replace it. The central content of a QMainWindow is a QWidget, so create one widget that does what you want and set it using setCentralWidget.
-
wrote on 20 Jul 2018, 06:59 last edited by Narasimha Reddy MV
You are Creating Layout inside a widget so Don't use (Parent Instance) 'this' pointer.
Layout_page3 = new QHBoxLayout;
try this it will work
-
wrote on 16 Apr 2021, 10:46 last edited by
Good afternoon every one!
I encour this issue too, Msg is:18:28:21: Debugging starts
QLayout: Attempting to add QLayout “” to MainWindow “MainWindow”, which already has a layoutReason:
I used the following In QMainwindow:
====error code=> QGridLayout *t_gridLayout_map = new QGridLayout(this);
Solution:
remove "this" as the following:
====OK code=> QGridLayout *t_gridLayout_map = new QGridLayout();That's OK!
have a good day! -
Good afternoon every one!
I encour this issue too, Msg is:18:28:21: Debugging starts
QLayout: Attempting to add QLayout “” to MainWindow “MainWindow”, which already has a layoutReason:
I used the following In QMainwindow:
====error code=> QGridLayout *t_gridLayout_map = new QGridLayout(this);
Solution:
remove "this" as the following:
====OK code=> QGridLayout *t_gridLayout_map = new QGridLayout();That's OK!
have a good day!wrote on 16 Apr 2021, 12:16 last edited by@Qterry-wang said in QLayout: attempting to add QLayout "" to MainWindow, which already has a layout (solved):
QGridLayout *t_gridLayout_map = new QGridLayout();
This does not address the issue. It merely creates a currently-unparented
QGridLayout
, it depends what you then do with that. You cannot then add it directly tothis
, theMainWindow
, since that already has a layout. -
Good afternoon every one!
I encour this issue too, Msg is:18:28:21: Debugging starts
QLayout: Attempting to add QLayout “” to MainWindow “MainWindow”, which already has a layoutReason:
I used the following In QMainwindow:
====error code=> QGridLayout *t_gridLayout_map = new QGridLayout(this);
Solution:
remove "this" as the following:
====OK code=> QGridLayout *t_gridLayout_map = new QGridLayout();That's OK!
have a good day!wrote on 2 Jul 2024, 05:14 last edited by@Qterry-wang wow I was also getting similar warning and i deleted parameter like you, warning was gone. THX !