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

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.

    Thanks
    Jeff



  • Have a look at QStackedWidget



  • You could use
    QLabel.setPixmap(..)
    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

    Hi,

    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