QTextEdit initial show



  • My application's MainWindow has a QTextEdit widget which displays some text. What I want to do is to change the font size of the text in the QTextEdit widget before I initially display the MainWindow at application start. The font size is stored in my app settings, and those settings are retrieved and applied during the MainWindow's constructor code execution cycle. I just can't figure out where in the code I should change the font size so that when the widget is displayed the font size is already changed. I have no problem changing the font size "after" the widget is displayed.

    My MainWindow's event handler is used to handle QTextEdit's events

        ui->textEdit->installEventFilter(mainWindow);
    
    

    but I am not sure which event i should be monitoring for to make sure that the QTextEdit is about to be displayed so that I can apply my font size change

    EDIT (SOLVED):
    Only a few minutes after I posted my question, I figured it out.
    If i check for WindowActivate event and do my font size change then, everything works as I expected. Other events like Paint, Show and ShowToParent did not work.



  • This post is deleted!

  • Moderators

    Hi, I know it's solved, but I think you complicated it a little unnecessarily.

    Since your textEdit is constructed via designer (I'm guessing because of the ui->textEdit part), and you're also loading the setting in the constructor, then you can just directly apply them there. Obviously everything that happens in the constructor is waay before anything is shown.

    Besides, you used WindowActivate event, which will happen multiple times, whenever, well, the window gets activated. I'm guessing you just want it once at initialization.

    So something like:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QFont font = loadItFromSettingsHere();
        ui->textEdit->setFont(font);
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.