The standard implementation of QTextEdit.zoomIn/Out simply modifies the pointSize base font for text editing.
The method used in this example to change the font size wraps the selected word with a span tag and uses the built-in css to set the font-size property to a fixed value. This means that with a subsequent increase in the editing text, only the invariable text will be affected.
It would be possible to overcome this problem using relative font sizes. However, it seems that only a limited subset of css properties is supported, so it can only be set to inaccurate values ββsuch as small , large , etc.
This can be implemented in this example by making the following changes:
# Font Size self.comboSize = QtGui.QComboBox(self.toolBar) self.toolBar.addWidget(self.comboSize) self.comboSize.addItem('small') self.comboSize.addItem('medium') self.comboSize.addItem('large') self.comboSize.addItem('x-large') self.comboSize.addItem('xx-large') self.comboSize.setCurrentIndex(1) self.comboSize.activated[int].connect(self.textSize) def textSize(self, size): fmt = QtGui.QTextCharFormat() fmt.setProperty(QtGui.QTextFormat.FontSizeAdjustment, size - 1) self.mergeFormatOnWordOrSelection(fmt)
source share