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?
Simply use the setFont() method on the QApplication or QWidget : QFont font("Courier New"); font. setStyleHint(QFont::Monospace); QApplication::setFont(font);
To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.
use setFont() : it sets the default font for the target; you can get the current default font using something. font() , then use font. setPointSize() (or setPointSizeF() for float values, if the font allows it) and then call setFont(font) on the target.
Select Fonts & Colors tab. Under the Font heading after where it says Family: select Source Code Pro from the dropdown menu as marked by the mouse cursor in the below screenshot. After where it says Size: select 10 from the dropdown menu. Font size 10 is the best font size in my Qt Creator.
Functions like QTextEdit.setFontPointSize
work on the current format. If you want to change all the font sizes at once, you need to set the size of the base font, like this:
font = QtGui.QFont()
font.setPointSize(16)
self.editor.setFont(font)
Note that you can also change the relative size of the base-font using the zoomIn and zoomOut slots. The implementation of those slots changes the base-font size in exactly the same way as shown above.
I found full solution. You should:
textCursor
selectAll
setFontPointSize
setTextCursor
to clear selectionIn 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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With