Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextEdit initial show

QTextEdit initial show

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 644 Views
  • 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.
  • a8wzA Offline
    a8wzA Offline
    a8wz
    wrote on last edited by a8wz
    #1

    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
    0
    • a8wzA Offline
      a8wzA Offline
      a8wz
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved