我认为问题可能是标签居中,但它没有填满你认为它的空间.您可以通过更改标签背景颜色进行验证.以下示例适用于Windows 7:
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Window(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
self.label = QLabel("Test", self)
self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.label.setAlignment(Qt.AlignCenter)
self.label.setStyleSheet("QLabel {background-color: red;}")
self.button = QPushButton("Test", self)
self.layout = QGridLayout()
self.layout.addWidget(self.label, 0, 0)
self.layout.addWidget(self.button, 0, 1)
self.setLayout(self.layout)
self.show()
app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())