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. Forcing QGraphicsWidget::setGeometry to execute....?
Qt 6.11 is out! See what's new in the release blog

Forcing QGraphicsWidget::setGeometry to execute....?

Scheduled Pinned Locked Moved Solved General and Desktop
guisetgeometryqgraphicsitemqgraphicswidgetresize
7 Posts 4 Posters 334 Views 2 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.
  • J Offline
    J Offline
    Jammin44fm
    wrote last edited by
    #1

    Hi all,

    I'm trying to figure out how to force QGraphicsWidget::setGeometry to fully execute - even when I'm passing in a geometry that is exactly the same as the current geometry for that widget.

    In my code I have a section that calls QGraphicsWidget::resize(width, height);
    Which then internally calls QGraphicsWidget::setGeometry(width, height)
    Sometimes users come across a corner case where large parts of the GUI has changed and been redrawn, but this specific part has the same geometry, thus internally the QGraphicsWidget::setGeometry call early outs, based on the following code from qgraphicswidget.cpp Ln. 344

    if (newGeom == d->geom)
       return;
    

    However the rest of my code depends on signals that are emitted from within the setGeometry function,
    and in this edge case, parts of my GUI don't get drawn in correctly.

    So my question is:
    Is there a easy / cheap way to force the internal setGeometry function to fully execute?
    I've tried the following

                mGraphicsWidget->layout()->setInstantInvalidatePropagation(true);
                mGraphicsWidget->layout()->invalidate();
    

    But it doesn't do what I need.
    Doing a...

                mGraphicsWidget->resize(0, 0);
    

    Prior to the resize, DOES work, but it seems like an unnecessary duplication of work?

    Is there a faster, more effective way of modifying the internal state of the QGraphicsWidget,
    ( ie. the QGraphicsLayoutItemPrivate d->geom that will allow the actual setGeometry to fully execute?)

    Cheers,
    James

    JonBJ Pl45m4P jeremy_kJ 3 Replies Last reply
    0
    • J Offline
      J Offline
      Jammin44fm
      wrote last edited by
      #2

      I've also discovered that
      ~mGraphicsWidget->adjustSize();
      has the desired effect, But i see that internally this is just doing a setGeometry() with the preferred size for this object - so we are still doing a 2 setGeometry() calls :(

      1 Reply Last reply
      0
      • J Jammin44fm

        Hi all,

        I'm trying to figure out how to force QGraphicsWidget::setGeometry to fully execute - even when I'm passing in a geometry that is exactly the same as the current geometry for that widget.

        In my code I have a section that calls QGraphicsWidget::resize(width, height);
        Which then internally calls QGraphicsWidget::setGeometry(width, height)
        Sometimes users come across a corner case where large parts of the GUI has changed and been redrawn, but this specific part has the same geometry, thus internally the QGraphicsWidget::setGeometry call early outs, based on the following code from qgraphicswidget.cpp Ln. 344

        if (newGeom == d->geom)
           return;
        

        However the rest of my code depends on signals that are emitted from within the setGeometry function,
        and in this edge case, parts of my GUI don't get drawn in correctly.

        So my question is:
        Is there a easy / cheap way to force the internal setGeometry function to fully execute?
        I've tried the following

                    mGraphicsWidget->layout()->setInstantInvalidatePropagation(true);
                    mGraphicsWidget->layout()->invalidate();
        

        But it doesn't do what I need.
        Doing a...

                    mGraphicsWidget->resize(0, 0);
        

        Prior to the resize, DOES work, but it seems like an unnecessary duplication of work?

        Is there a faster, more effective way of modifying the internal state of the QGraphicsWidget,
        ( ie. the QGraphicsLayoutItemPrivate d->geom that will allow the actual setGeometry to fully execute?)

        Cheers,
        James

        JonBJ Online
        JonBJ Online
        JonB
        wrote last edited by
        #3

        @Jammin44fm said in Forcing QGraphicsWidget::setGeometry to execute....?:

        if (newGeom == d->geom)
        return;

        Given this I assume you need to have a changed geometry. Use an adjustSize() or temporarily set its geometry to 1 more or less than it should be and set it back. Or change whatever in your code so that it does not need a setGeometry signal where it has not actually changed.

        1 Reply Last reply
        0
        • J Jammin44fm

          Hi all,

          I'm trying to figure out how to force QGraphicsWidget::setGeometry to fully execute - even when I'm passing in a geometry that is exactly the same as the current geometry for that widget.

          In my code I have a section that calls QGraphicsWidget::resize(width, height);
          Which then internally calls QGraphicsWidget::setGeometry(width, height)
          Sometimes users come across a corner case where large parts of the GUI has changed and been redrawn, but this specific part has the same geometry, thus internally the QGraphicsWidget::setGeometry call early outs, based on the following code from qgraphicswidget.cpp Ln. 344

          if (newGeom == d->geom)
             return;
          

          However the rest of my code depends on signals that are emitted from within the setGeometry function,
          and in this edge case, parts of my GUI don't get drawn in correctly.

          So my question is:
          Is there a easy / cheap way to force the internal setGeometry function to fully execute?
          I've tried the following

                      mGraphicsWidget->layout()->setInstantInvalidatePropagation(true);
                      mGraphicsWidget->layout()->invalidate();
          

          But it doesn't do what I need.
          Doing a...

                      mGraphicsWidget->resize(0, 0);
          

          Prior to the resize, DOES work, but it seems like an unnecessary duplication of work?

          Is there a faster, more effective way of modifying the internal state of the QGraphicsWidget,
          ( ie. the QGraphicsLayoutItemPrivate d->geom that will allow the actual setGeometry to fully execute?)

          Cheers,
          James

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote last edited by
          #4

          @Jammin44fm said in Forcing QGraphicsWidget::setGeometry to execute....?:

          Is there a easy / cheap way to force the internal setGeometry function to fully execute?

          Forcing a complete re-draw with new geometry is never "cheap" or efficient. That would also require prepareGeometryChange() to be called, so the view/scene knows what is going to happen next.
          Most QGraphicsItems invalidate their boundingRect in this case and re-create it on next paint() with updated geometry and matching content.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • J Jammin44fm

            Hi all,

            I'm trying to figure out how to force QGraphicsWidget::setGeometry to fully execute - even when I'm passing in a geometry that is exactly the same as the current geometry for that widget.

            In my code I have a section that calls QGraphicsWidget::resize(width, height);
            Which then internally calls QGraphicsWidget::setGeometry(width, height)
            Sometimes users come across a corner case where large parts of the GUI has changed and been redrawn, but this specific part has the same geometry, thus internally the QGraphicsWidget::setGeometry call early outs, based on the following code from qgraphicswidget.cpp Ln. 344

            if (newGeom == d->geom)
               return;
            

            However the rest of my code depends on signals that are emitted from within the setGeometry function,
            and in this edge case, parts of my GUI don't get drawn in correctly.

            So my question is:
            Is there a easy / cheap way to force the internal setGeometry function to fully execute?
            I've tried the following

                        mGraphicsWidget->layout()->setInstantInvalidatePropagation(true);
                        mGraphicsWidget->layout()->invalidate();
            

            But it doesn't do what I need.
            Doing a...

                        mGraphicsWidget->resize(0, 0);
            

            Prior to the resize, DOES work, but it seems like an unnecessary duplication of work?

            Is there a faster, more effective way of modifying the internal state of the QGraphicsWidget,
            ( ie. the QGraphicsLayoutItemPrivate d->geom that will allow the actual setGeometry to fully execute?)

            Cheers,
            James

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote last edited by
            #5

            @Jammin44fm said in Forcing QGraphicsWidget::setGeometry to execute....?:

            However the rest of my code depends on signals that are emitted from within the setGeometry function,

            My instinct is that the rest of the code is wrong. Signaling a geometry change appears to be used as a proxy for something else. What is that something else?

            Asking a question about code? http://eel.is/iso-c++/testcase/

            J 1 Reply Last reply
            0
            • jeremy_kJ jeremy_k

              @Jammin44fm said in Forcing QGraphicsWidget::setGeometry to execute....?:

              However the rest of my code depends on signals that are emitted from within the setGeometry function,

              My instinct is that the rest of the code is wrong. Signaling a geometry change appears to be used as a proxy for something else. What is that something else?

              J Offline
              J Offline
              Jammin44fm
              wrote last edited by
              #6

              @jeremy_k

              Yeah it's increasingly looking like this is the case.
              It's a pretty rare edge case in the code, so I need to consider if a larger refactor is worth the time and effort.

              1 Reply Last reply
              0
              • J Jammin44fm has marked this topic as solved
              • J Offline
                J Offline
                Jammin44fm
                wrote last edited by
                #7

                I've marked this as solved.
                Whilst I didn't get a perfect / ideal answer, I Did some good responses and enough information to make a decision for my use case.
                In the end I decided that a refactor would be too much work, and while i came up with other more elegant solutions, they really all just boiled down to an extra call to setGeometry, so i ended up going with the existing fix.

                Thanks everyone though.

                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