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. QGraphicsItem paint event called continually during QWidget::event loop

QGraphicsItem paint event called continually during QWidget::event loop

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 3 Posters 13.3k 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.
  • Q Offline
    Q Offline
    qtshah
    wrote on last edited by
    #6

    My mistake there is a layout in the Frame class.

    QHBoxLayout * layout = new QHBoxLayout;
    layout->addWidget(myGraphicsView);
    setLayout(layout);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #7

      So now it's working as you want ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtshah
        wrote on last edited by
        #8

        No the paint method is still being called repeatedly for each rectangle in the scene, which is time consuming. I only want paint to be called when something changes in the rectangle like when it is moved or the color is changed. It may be that I am misunderstanding when the paint method is triggered. Is it supposed to be triggered at every QWidget event? Because that is what seems to be happening right now.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #9

          One other detail, you are not calling the correct base class implementation of MainWindow.

          Also, do you really need Frame ? Looks like you could put the QGraphicsView directly as central widget, no ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • Q Offline
            Q Offline
            qtshah
            wrote on last edited by
            #10

            No the QFrame is not necessary, we will need to refactor that. I'm not sure what you mean by not calling the correct base class implementation. Are you referring to the QMainWindow constructor?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #11

              In MainWindow::event, you are not calling QMainWindow::event but QWidget::event.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • Q Offline
                Q Offline
                qtshah
                wrote on last edited by
                #12

                Oh yes that is true. I tried switching it to QMainWindow::event but the result was the same

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  What else are you doing in your application ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    qtshah
                    wrote on last edited by
                    #14

                    We have a palette of icons in a dock widget that the user can add into the scene, copy, paste and delete. Each graphics item has a proxy widget that holds properties for the item. The items are rectangles and lines that connect between them so that moving a rectangle should move the lines that are connected to it. I want the items to update at a reasonable event, for example a mouse release event, instead of repeatedly like they doing now which is causing some lag. Basically I want to install an event filter, but am first trying to understand why all QMainWindow events are triggering a graphics item paint.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      By proxy do you mean you have QProxyGraphicsProxyWidget ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        qtshah
                        wrote on last edited by
                        #16

                        yes that's it

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #17

                          How many are they at once on your scene ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • Q Offline
                            Q Offline
                            qtshah
                            wrote on last edited by
                            #18

                            There's no limit to how many can be in the scene and the scenes are likely to get complicated . Most likely there will be between ~10 and ~50 items at a time.

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #19

                              Are you still experiencing that if you avoid the proxy widgets ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • Q Offline
                                Q Offline
                                qtshah
                                wrote on last edited by
                                #20

                                Yes we are

                                1 Reply Last reply
                                0
                                • Q Offline
                                  Q Offline
                                  qtshah
                                  wrote on last edited by qtshah
                                  #21
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #22

                                    Is the code accessible somewhere to be tested ?

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • Q Offline
                                      Q Offline
                                      qtshah
                                      wrote on last edited by qtshah
                                      #23

                                      Hi sorry for the late response. We figured out the problem. Within the paint function of the rectangle we were updating the line and this was causing an infinite paint loop. Thank you for your help!

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #24

                                        Glad you found out and thanks for sharing !

                                        Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        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