我正在做一些随机选择器,在那里可以显示键入用户的信息。(我使用文本浏览器),如何设置文本始终居中对齐?
self.textBrowser.setText(newList + "\n\nanalyzing in ...")
QtTest.QTest.qWait(1000)
self.textBrowser.setText(newList + "\n\nanalyzing in ..." + "\n\n 3")
答案 0 :(得分:0)
QTextBrowser Class
继承:QTextEdit
QTextEdit :: setAlignment(Qt :: Alignment)
将当前段落的对齐方式设置为a。有效的对齐方式是Qt :: AlignLeft,Qt :: AlignRight,Qt :: AlignJustify和Qt :: AlignCenter(水平居中)。
抱歉,我有PyQt5:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Win(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.i = 5
self.textBrowser = QtWidgets.QTextBrowser()
self.textBrowser.setAlignment(QtCore.Qt.AlignCenter) # <-------------
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.textBrowser)
self.setLayout(layout)
timer = QtCore.QTimer(self, interval=1000, timeout=self.print_out)
timer.start()
def print_out(self, string="Hello world!"):
self.textBrowser.append(string + "\n\nanalyzing in ...\n {}".format('----' * self.i))
self.i += 1
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
myWin = Win()
myWin.show()
sys.exit(app.exec_())