Home > database >  Is there a way to keep widget always in centre in pyqt QHBoxLayout
Is there a way to keep widget always in centre in pyqt QHBoxLayout

Time:01-05

I want to know if it is possible to keep a widget always centred inside a QHBoxLayout.

For Example: I want to make wid1 centred that it won't change its position at all

......wid1......
......wid1..wid2
wid2..wid1......
wid2..wid1..wid3

CodePudding user response:

please add more information to your question

if you want to center align a label you can use this line:

from PyQt5 import QtCore
self.label.setAlignment(QtCore.Qt.AlignCenter)

CodePudding user response:

you are using QHbox which aligns them horizontaly what you want to use is one that aligns them vertically like QVBoxLayout or in a grid like QGridLayout then use the alignment form my previous answer to align it center

hbox.addWidget(Widget, alignment=QtCore.Qt.AlignCenter)

but even if you have other widgets aligned center it would then move a bit to the right or left

  • Related