简体   繁体   中英

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

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

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)

Edit:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM