PDA

View Full Version : QTextEdit and formatting



fusycmr
6th July 2012, 09:25
Hi.
I have a QTextEdit. And I have a task to change formatting of the text in text edit.
First task is to set initial font size. I tried numerous variants:
1:
QTextCharFormat cf;
cf.setFontPointSize(14);
completedTextEdit->setCurrentCharFormat(cf);
2:
completedTextEdit->setStyleSheet ( "font: 14px" );
3:
completedTextEdit->setFontPointSize(14);
4:
method with setFont (did not work for my surprise)

All that methods (first 3). But I have problem when using setting font size. If I call zoomIn and zoomOut they do not work. And this functions work well if i don't use setting size.

wysota
6th July 2012, 09:56
QTextDocument::defaultFont

fusycmr
6th July 2012, 10:53
I have tried following code:
QFont f;
f.setPointSize ( 20 );
completedTextEdit->document ()->setDefaultFont ( f );

It does not work...

wysota
6th July 2012, 11:26
Maybe the document doesn't use the default font. Please provide a minimal compilable example reproducing the problem.

chriskon149
9th July 2012, 05:14
I have tried following code:
QFont f;
f.setPointSize ( 20 );
completedTextEdit->document ()->setDefaultFont ( f );

It does not work...

Try doing
QFont f = completedTextEdit->font(); //Get the current font
f.setPointSize(20);
completedTextEdit->setFont(f);

If I recall correctly, when I did something like this a few months ago I had to get the current font (and store it temporarily to work on), THEN change its size, THEN set the QTextEdit's font to the modified font.

Chris

Edit: Incorrectly capitalized the variable.