python-2.7pyqtpyqt4qtexteditqtextcursor

How to change the fontsize for everything inside QTextEdit in PyQt4?


I have a QTextEdit widget whose contents are populated programmatically using QTextEdit.textCursor.

My plan is to let the user view the populated information in the QTextEdit, edit the text if necessary, and later print to a PDF file using QPrinter.

However, I would like to change the font size of the entire contents of the QTextEdit before allowing the user to edit the text. I just need to set the contents to a single font size; there is no need to accommodate multiple font sizes.

I have tried using QTextEdit.setFontSize(16) both before and after the textCursor operation but it doesn't seem to have any effect.

How do I change the font size of the contents of a QTextEdit widget?


Solution

  • I found full solution. You should:

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

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