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. How to detecting finish QEvent::Paint
Forum Updated to NodeBB v4.3 + New Features

How to detecting finish QEvent::Paint

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 6.2k Views 3 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Your question is equivalent to "how do I know what happens in the future?" and the answer is: you don't.
    Events (especially painting) can be triggered by plethora of stuff, a lot of them outside of your app control.

    Generally you should react to occurring events and not anticipate them or assume one will come or not.

    What are you trying to do exactly? Maybe it's the case of "the wrong question for the right reason"?

    1 Reply Last reply
    0
    • H HAHAHAHAHA

      I have class and i cacth event paint and call function. But event run multiple (show, resize...). How do I know that this event is the last event? Please help me!

      bool MyWidgetView::event ( QEvent * event )
      {
      if ( (event->type() == QEvent::Paint))
      {
      // call function Draw
      }
      bool rc = QWidget::event(event);
      return rc;
      }

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #3

      @HAHAHAHAHA
      To add to what Chris Kawa said, you should not depend on the order of events. The events are (usually) generated from the system and there's no guarantee that you get a resize after show, it might be quite the opposite depending on the OS/platform.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Hi can I ask why you want to know last paint event (even if there is no last)
        Also is there a reason that you cannot use the normal paint ?
        void paintEvent(QPaintEvent*)

        _Hien_VN_ 1 Reply Last reply
        0
        • H Offline
          H Offline
          HAHAHAHAHA
          wrote on last edited by HAHAHAHAHA
          #5

          Thank all.
          I'm using an API to draw. But when you finish painting the Paint event of Qt happen so my drawings were obscured. Now i can fix it by call function update draw before 50ms.

          bool MyClass::event ( QEvent * event )
          {
          
              if ((event->type() == QEvent::Paint))
              {
                         QTimer::singleShot(50, this, SLOT(updateDraw()));
              }
              bool rc = QWidget::event(event);
          return rc;
          }
          

          Or

          void MyClass::paintEvent(QPaintEvent *e)
          {
                 QTimer::singleShot(50, this, SLOT(updateDraw()));
          }
          

          But it is not a good way. Because it was called several times. :((

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #6

            @HAHAHAHAHA said:

            void MyClass::paintEvent(QPaintEvent *e)
            {
            QTimer::singleShot(50, this, SLOT(updateDraw()));
            }

            Don't do that. That's not how painting is suppose to work. As I said - paint event is called whenever a widget needs to be repainted. This can happen because of a window resize, because it gained focus, state of some widget changed or something called update() or repaint(). There are a lot more possible triggers. And yes, this will happen multiple times during your app lifetime and quite often. In general, you can't anticipate when it happens, but whenever it does you should paint immediately current state of the widget and as quickly as possible. If you want to force painting at some point call update() and Qt will schedule a paint event.

            What are you trying to do exactly? It looks like you're fighting against the framework.

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi can I ask why you want to know last paint event (even if there is no last)
              Also is there a reason that you cannot use the normal paint ?
              void paintEvent(QPaintEvent*)

              _Hien_VN_ Offline
              _Hien_VN_ Offline
              _Hien_VN
              wrote on last edited by
              #7

              @mrjj Hi, we already used the method void paintEvent(QPaintEvent*) as you suggested, but my drawing did not display.
              The reason that we ask the last paint event is to put call method specify drawing (it is supported by third part api) after update() of Qt. In case drawing big data then drawing executing called many, so performance of its very slowly.
              Pls help us and give any advance!

              mrjjM 1 Reply Last reply
              0
              • _Hien_VN_ _Hien_VN

                @mrjj Hi, we already used the method void paintEvent(QPaintEvent*) as you suggested, but my drawing did not display.
                The reason that we ask the last paint event is to put call method specify drawing (it is supported by third part api) after update() of Qt. In case drawing big data then drawing executing called many, so performance of its very slowly.
                Pls help us and give any advance!

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

                @_Hien_VN
                Hi , i think we need more info on how you draw this other drawing
                as it seems to be the key to understand what you are doing.

                Beware that before a paint event, the widgets area is cleared with background color.
                I wonder if this is why your drawing dont show.
                u can disable it with
                widget->setAttribute(Qt::WA_NoSystemBackground);

                If that dont do it for you , u need to show the code for updateDraw as you can not in
                any good way know when the last paint event is.
                It will never be a solid solution. :)

                _Hien_VN_ 1 Reply Last reply
                0
                • mrjjM mrjj

                  @_Hien_VN
                  Hi , i think we need more info on how you draw this other drawing
                  as it seems to be the key to understand what you are doing.

                  Beware that before a paint event, the widgets area is cleared with background color.
                  I wonder if this is why your drawing dont show.
                  u can disable it with
                  widget->setAttribute(Qt::WA_NoSystemBackground);

                  If that dont do it for you , u need to show the code for updateDraw as you can not in
                  any good way know when the last paint event is.
                  It will never be a solid solution. :)

                  _Hien_VN_ Offline
                  _Hien_VN_ Offline
                  _Hien_VN
                  wrote on last edited by
                  #9

                  @mrjj Hi, we tried it as your suggestion with flow logic as below:

                  • initial widget, then widget->setAttribute(...)
                  • call update()
                  • call paint()
                    OR
                  • initial widget, then widget->setAttribute(...)
                  • call paint()
                  • call update()
                    The result not change, drawing flicker then not display.
                  mrjjM 1 Reply Last reply
                  0
                  • _Hien_VN_ _Hien_VN

                    @mrjj Hi, we tried it as your suggestion with flow logic as below:

                    • initial widget, then widget->setAttribute(...)
                    • call update()
                    • call paint()
                      OR
                    • initial widget, then widget->setAttribute(...)
                    • call paint()
                    • call update()
                      The result not change, drawing flicker then not display.
                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @_Hien_VN
                    hi
                    ok. it was worth a shot.
                    It sounds like you are sort of drawing on top of the widget for your "drawing"

                    Can you show some more how updateDraw works ?

                    _Hien_VN_ 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @_Hien_VN
                      hi
                      ok. it was worth a shot.
                      It sounds like you are sort of drawing on top of the widget for your "drawing"

                      Can you show some more how updateDraw works ?

                      _Hien_VN_ Offline
                      _Hien_VN_ Offline
                      _Hien_VN
                      wrote on last edited by
                      #11

                      @mrjj hi, do you know cad viewer? we are using it to draw.

                      mrjjM 1 Reply Last reply
                      0
                      • _Hien_VN_ _Hien_VN

                        @mrjj hi, do you know cad viewer? we are using it to draw.

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

                        @_Hien_VN
                        but how do you make it draw into the widget?
                        via HWND ? or DC ?
                        If its not a Qt program, how can it even draw into the widget?
                        It draws on top of the widget?

                        _Hien_VN_ 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @_Hien_VN
                          but how do you make it draw into the widget?
                          via HWND ? or DC ?
                          If its not a Qt program, how can it even draw into the widget?
                          It draws on top of the widget?

                          _Hien_VN_ Offline
                          _Hien_VN_ Offline
                          _Hien_VN
                          wrote on last edited by
                          #13

                          @mrjj Hi, we used HWND, please refer source as below:
                          RECT rc;
                          GetClientRect((HWND)this->effectiveWinId(), &rc);

                          mrjjM 1 Reply Last reply
                          0
                          • _Hien_VN_ _Hien_VN

                            @mrjj Hi, we used HWND, please refer source as below:
                            RECT rc;
                            GetClientRect((HWND)this->effectiveWinId(), &rc);

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

                            @_Hien_VN
                            Hi
                            That just gives a rect from a hwnd.

                            How do you make the cad viewer draw on the widget?

                            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