Qt World Summit: Register Today!

QStackedLayout added to mainwindow layout automatically, Why?

  • I am currently writing a program using Qt's GUI. in the contructor of the main window I declare a QStackedLayout without any options in the constructors arugments. then I set the layout with the newly declared layout. for some reason when I run the code it says
    "QWidget::setLayout: Attempting to set QLayout "" on REDcap_GUI "", which already has a layout"
    If I were to remove the line to set the layout, It works just fine. Does Qt know to automatically add it to the layout? All tutorials have a line to add a stackedlayout to the to the main window.

  • Ok problem solved. I was using QMainWindow as my windows manager. Apprently you are suppose to use setCentralWidget. Doing this resolved many other issues too.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Indeed, QMainWindow already has a layout which handles its complex content e.g. toolbars, status bar, dock widgets etc.

    You can also consider QStackedWidget for your central widget, it will avoid to have a placeholder widget to set your QStackedLayout on.

Log in to reply