SetAlignment for QStackedLayout

  • Hello,

    I use a QStackedWidget, and append a QLabel to it, I want this QLabel to be centered vertically as well as horizontally. I tried using my_stack.layout().setAlignment(QtCore.Qt.AlignCenter) as well as my_stack.layout().setAlignment(my_label, QtCore.Qt.AlignCenter) but none would work.

    Why does the alignment does not take effect as it does with QBoxLayout?

    Should I use the QStackedLayout alone instead? Perhaps the layout alignment must be set before the layout itself is set?

    Thanks for the help.

  • PS: I just tried using the QStackedLayout directly and setting the Alignment before setting the layout did not help.

  • I can't figure out what the matter is with QStackedLayout, but I worked around it by placing a QFrame in that layout, with a QHBoxLayout and a centered widget.

  • Using QStackedWidget would have worked just fine, you only needed to set a layout on each of the pages in it. That would have centered your label just fine.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.