Qt World Summit: Register Today!

Exchange images at the same position

  • Hi,

    in earlier days (VCL, C# Windows Forms) when I had to toggle between two images at the same location in a window I placed those two images at the very same location and toggled their visibility.
    How would I achieve such behaviour with Qt?

    I just started programming with Qt and I cannot find any simple way :-( When I have a label with a pixmap, I cannot put two of them to the same position. At least the layout system in Qt Designer doesn't seem to allow this.
    Even if I would think about resetting the pixmap (what would be the best way then?) I wonder how one can use overlapping elements.


  • Have a look at QStackedWidget

  • You could use
    And just use one label, no overlapping

    If you want overlapping, a QGridLayout let you to have element on top of another.
    Just insert them in the same row, column and toggle visibility of the one you need

    Good luck!

  • Lifetime Qt Champion


    For "overlapping" rather than the QGridLayout, a QStackedLayout or as suggested by by @matze42 a QStackedWidget it the way to go.

  • Thank you all - QStackedWidget helps!

Log in to reply