zephyr
zephyr

Reputation: 2332

PyQt QTextEdit forgetting settings

I've got a PyQt GUI with a QTextEdit in it. I have set a few of the widget settings to play with things like the font size. What I'm seeing is that when I initially type in the field, the settings are applied, but if I delete all text and start typing again, the settings have reset to the default ones. Below is a MWE where I can see this behavior. Just in case it matters, I'm using Python 3.5.1 with 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()

Upvotes: 0

Views: 437

Answers (1)

dterpas
dterpas

Reputation: 161

You can create a new QFont item and then you can use QTextEdit.setFont()

This way it will not reset after all text is deleted.

Upvotes: 1

Related Questions