gpt4 book ai didi

python - 将 QLCDNumber 文本右对齐

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:58 25 4
gpt4 key购买 nike

我有 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_())

enter image description here

关于python - 将 QLCDNumber 文本右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53354686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com