我有QGridLayout我在其中插入QLCDNumber,如下所示:
self.mainLayout.addWidget(display, 0, 0, 1 , 5)
一切都很好,但是窗口缩放时,数字(默认为0)从中心向右“移动”。有人可以给我一个提示,如何防止QLCDNumber缩放,并使其中的文本向右对齐?
最佳答案
尝试一下:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Window(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.lcd = QLCDNumber()
self.lcd.setFixedSize(150, 70) # Set the size you want
self.lcd.display(12345)
centralWidget = QWidget()
self.setCentralWidget(centralWidget)
self.mainLayout = QGridLayout(centralWidget)
self.mainLayout.addWidget(self.lcd, 0, 0, Qt.AlignRight) # Set the alignment option
self.mainLayout.addWidget(QTextEdit("TextEdit..."), 1,0)
self.mainLayout.addWidget(QPushButton("Button"), 2,0, Qt.AlignCenter)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Window()
ex.show()
sys.exit(app.exec_())
关于python - 将QLCDNumber文本向右对齐,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53354686/