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. When will a widget show up, after calling .show() or after entering its paint event?
Qt 6.11 is out! See what's new in the release blog

When will a widget show up, after calling .show() or after entering its paint event?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    David406
    wrote on last edited by David406
    #1

    Hi all, as stated in the title, I'm not quite clear about the difference between a paint event and
    the .show() method of widgets. As I see it, the widget window will show up after entering its
    paint event. Because in my recent coding, I found in the debug mode that after steping over
    .show() method, the widget stays hidden until it enters the paint event method.

    But I'm not quite sure whether I'm right, or the project I encountered is just a special (or different) case.
    Could anyone please give some clarifications?

    mrjjM 1 Reply Last reply
    0
    • D David406

      Hi all, as stated in the title, I'm not quite clear about the difference between a paint event and
      the .show() method of widgets. As I see it, the widget window will show up after entering its
      paint event. Because in my recent coding, I found in the debug mode that after steping over
      .show() method, the widget stays hidden until it enters the paint event method.

      But I'm not quite sure whether I'm right, or the project I encountered is just a special (or different) case.
      Could anyone please give some clarifications?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @David406

      Hi
      Show will set the Widgets state to visible and
      update() that will post a paint event to the event queue.

      When you are debugging (stepping), you are stopping the loop so here its clear
      to see that show() does not make it be on screen. The paint will.

      So paint event is the actual function that shows something on the screen.

      D 1 Reply Last reply
      4
      • mrjjM mrjj

        @David406

        Hi
        Show will set the Widgets state to visible and
        update() that will post a paint event to the event queue.

        When you are debugging (stepping), you are stopping the loop so here its clear
        to see that show() does not make it be on screen. The paint will.

        So paint event is the actual function that shows something on the screen.

        D Offline
        D Offline
        David406
        wrote on last edited by
        #3

        @mrjj
        Thanks!
        It makes sense now!

        mrjjM 1 Reply Last reply
        0
        • D David406

          @mrjj
          Thanks!
          It makes sense now!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @David406
          Super.
          This is also why looong
          for loops in code will make the app paint slow/ not at all.

          D 1 Reply Last reply
          0
          • mrjjM mrjj

            @David406
            Super.
            This is also why looong
            for loops in code will make the app paint slow/ not at all.

            D Offline
            D Offline
            David406
            wrote on last edited by
            #5

            @mrjj
            Hi,
            could you please elaborate a bit on your statement?
            Sorry but I'm quite new in this Qt world.

            mrjjM 1 Reply Last reply
            0
            • D David406

              @mrjj
              Hi,
              could you please elaborate a bit on your statement?
              Sorry but I'm quite new in this Qt world.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @David406
              Oh yes. ofc.
              Qt is what called event driven , like most desktop programs are.

              If we look at a normal main

              int mainx(int argc, char* argv[]) {
              QApplication a(argc, argv);
              MainWindow w;
              w.show();
              return a.exec(); <<<<< this is the event loop. programs is mostly in here.
              }

              So the event loop is running in the background and is used for sending signals / events from widgets to widgets.

              so if you have a loop in your code

              for (int var = 0; var < VERY_BIG_NUMBER; ++var) {
              do heavy calculations
              }

              You will not allow the loop ( a.exec() ) to get any work done and
              hence the application will appear to be hanging / not responding etc.
              Just like when you pause it with debugger.

              1 Reply Last reply
              3

              • Login

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