簡體   English   中英

PyQt QTextEdit忘記設置

[英]PyQt QTextEdit forgetting settings

我有一個帶有QTextEdit的PyQt GUI。 我已經設置了一些小部件設置來處理諸如字體大小之類的東西。 我看到的是,當我最初在該字段中鍵入內容時,將應用設置,但是如果我刪除所有文本並再次開始鍵入,則這些設置將重置為默認值。 下面是MWE,可以在其中看到此行為。 以防萬一,我正在將Python 3.5.1與PyQt4 4.8.7結合使用。

from PyQt4 import QtCore, QtGui

class App(object):

    def __init__(self):

        self.app = QtGui.QApplication([])   # The main application
        self.win = QtGui.QMainWindow()      # The main window
        self.widget = QtGui.QWidget()       # The central widget in the main window
        self.grid = QtGui.QVBoxLayout()     # The layout manager of the central widget

        self.textArea = QtGui.QTextEdit()
        self.grid.addWidget(self.textArea)
        self.textArea.setMinimumSize(600,300)
        self.textArea.setLineWrapMode(QtGui.QTextEdit.NoWrap)
        self.textArea.setFontPointSize(12)

        self.widget.setLayout(self.grid)
        self.win.setCentralWidget(self.widget)

        self.win.show()
        self.app.exec_()

App()

您可以創建一個新的QFont項,然后可以使用QTextEdit.setFont()

這樣,在刪除所有文本后將不會重置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM