Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Attempting to add QLayout "" to myWidget "myWidget", which already has a layout



  • Hello friends.

    I am developing a interface to my program. I have some widget implemented. I am using Graphics form to develop the widget and always I place the objects with graphics layout, not with code.

    When I finish a new widget, I always use the option "Lay Out in a Grid" in the main QWidget to place all the objects in the middle ( With spacers in top,bot,left and right side) and keep the objects in the same place when i select the fullscreen.

    Now I have created a new widget, I did the same that in the others but i receive the message "Attempting to add QLayout "" to myWidget "myWidget", which already has a layout".

    Solutions?


  • Lifetime Qt Champion

    Hi,

    What's the base class of myWidget ? If it's a QMainWindow, then it already has a layout that does all the magic that you get with that class (dock widget, toolbars, etc.).


  • Qt Champions 2019

    You're doing something like

    QWidget *w1 = new QWidget;
    QHBoxLayout *lay = new QHBoxLayout(w1);
    QHBoxLayout *lay2 = new QHBoxLayout(<whatever>);
    w1->setLayout(lay2);
    

    See also https://bugreports.qt.io/browse/QTBUG-69761


Log in to reply