How can I change the fontsize for everything inside a QTextEdit in PyQt4?

I have a widget QTextEdit

whose content is populated programmatically using QTextEdit.textCursor

.

My plan is to allow the user to view the filled-in information in QTextEdit

, edit the text as needed, and then print to PDF using QPrinter

.

However, I would like to change the font size of all content QTextEdit

before allowing the user to edit the text. I just need to set the content to one font size; there is no need to place fonts in different sizes.

I tried to use QTextEdit.setFontSize(16)

both before and after the operation textCursor

but it doesn't seem to have any effect.

How do I change the font size of the content of the widget QTextEdit

?

+4


source to share


2 answers


I found a complete solution. You must:

  • remember the current textCursor

  • call selectAll

  • call setFontPointSize

  • call setTextCursor

    to clear selection


In C ++, this can be done with the following code (this is just an example, but it solves your problem):

QTextCursor cursor = ui->textEdit->textCursor();
ui->textEdit->selectAll();
ui->textEdit->setFontPointSize(32);
ui->textEdit->setTextCursor( cursor );

      

+7


source


Functions such as QTextEdit.setFontPointSize

work with the current format. If you want to change all font sizes in one go, you need to set the base font size, for example:

    font = QtGui.QFont()
    font.setPointSize(16)
    self.editor.setFont(font)

      



Note that you can also change the relative size of the base font using zoomIn and zoomOut . The implementation of these slots resizes the base font in the same way as shown above.

+10


source







All Articles