Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QTextEdit initial show

    General and Desktop
    2
    3
    468
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • a8wz
      a8wz last edited by a8wz

      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.

      1 Reply Last reply Reply Quote 0
      • a8wz
        a8wz last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • Chris Kawa
          Chris Kawa Moderators last edited by Chris Kawa

          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);
          }
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post