0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Abhi Garg
  • 73
  • 7

1 Answers1

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