In my program, I am trying to automatically resize text size whenever the window size changes. I have used resizeEvent to do this and it is recognizing when the window is resized. However, whenever I try to change the font size using setFontPointSize it doesn't work. The only way I can get it to work is to use setText and use the HTML to change the font size, however, this is not desirable as I can't access widget size and variables inside the HTML.
Asked
Active
Viewed 311 times
1 Answers
0
when you change the font with setFontPointSize
you will do it for the new text, if you want it to apply to all the text you must select it and just change the font size:
class TextBrowser: public QTextBrowser{
protected:
void resizeEvent(QResizeEvent *event){
QTextBrowser::resizeEvent(event);
//some criteria to obtain the new font size
qreal size = 0.1*event->size().width();
QTextCursor cursor = textCursor();
selectAll();
setFontPointSize(size);
setTextCursor(cursor);
}
};
A complete example can be found in the following link

eyllanesc
- 235,170
- 19
- 170
- 241
-
Exactly what I was looking for. Thank you so much. I did Qt in the summer and completely forgot the syntax. – Abhi Garg Feb 17 '18 at 04:25
-
@AbhiGarg If my answer helps you, do not forget to mark it as correct. If you do not know how to do it, check the [tour] – eyllanesc Feb 17 '18 at 04:27
-
I marked it as correct. Could you also tell me the function for unselecting after? – Abhi Garg Feb 17 '18 at 23:27