Important: Please read the Qt Code of Conduct -

what's the difference between QStackedLayout and QStackedWidget?

  • what's the difference between QStackedLayout and QStackedWidget?

  • From the documentation
    QStackedWidget can be used to create a user interface similar to the one provided by QTabWidget. It is a convenience layout widget built on top of the QStackedLayout class.

  • Moderators

    Their APIs are different, although they share a lot of similarities. And one is a widget, while the other one is a layout.

  • for me , right now, i just want to use QStackedXXX to make 2 or more different widgets at the same place with the same size, to be visible just 1 widget at 1 time.
    will QStackedLayout more efficient?

  • Moderators

    It'd rather recommend to use the one that is more convenient for your GUI architecture. If you already have a layout in your GUI, then it is easier to instert a widget into it - in such case I would vote for using QStackedWidget.

    As for ""efficiency" depends on what you are interested in. CPU load? RAM usage? Number of CPU cache hits? You'll have to benchmark both solutions to get definite answers. I do not know whether any of the two is "better". The documentation claims QStackedWidget is done on top of QStackedLayout, but it is not inheritance (those classes are not related).

  • QStackedWidget has a QStackedLayout member

Log in to reply