Solved What is the red flag on centralWidget
-
When we open a new QWidget project we see a red flag :
What is this and is there anything wrong that we need to change and implement, as in one of my project it did disappear, and in other project where its still there if I do :
ui->centralWidget->layout()->setMargin(0); ui->centralWidget->layout()->setSpacing(0);
The code breaks and the program ends.
I know it means breaking the layout, but how in Central Widget?
-
@Arqam said in What is the red flag on centralWidget:
ui->centralWidget->layout()->setMargin(0);
If this line is crashing your app it means that either there is no central widget or the central widget does not have a layout. Very easy to find out using debugger or qDebug...
-
@Arqam said in What is the red flag on centralWidget:
What is this and is there anything wrong that we need to change and implement
This means you have no layout attached to that widget (you have a layout inside of it though). What you should do is break the inner layout, right click on the top-level widget and from the context menu select: "Lay out > Vertically". This will attach a vertical layout the widget (you won't see it with a red border) and put the child widgets inside it.
-
@kshegunov So say out widget is like this, so right clicking on the central widget doesn't give anything at that time.
-
@Arqam you need to right click on the toplvl item in your case QMainWindow - > Bottom most option in the popup menu is adding a layout.
-
@J.Hilk For that also we need at least one child element right
-
@Arqam IIRC, when you create a QMainWindow via QtDesigner, you'll always have 2 childen, the QWidget with the Objectname "centralWidget" and a QMenuBar.
-
Just click on the empty space and select the appropriate layout (see screenshot).