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. Get yet-not-shown widget's size -> BUG?
QtWS25 Last Chance

Get yet-not-shown widget's size -> BUG?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.9k 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.
  • V Offline
    V Offline
    viktor.benei
    wrote on last edited by
    #1

    I have to get a widget's position and size before it actually gets inserted to the layout and shown. (It's for a cross-page fading effect - basically: fade source out and target in, which I managed with a temporary widget which gets the snapshots from both source-page and target-page, makes the transition then replaces itself with the target).

    The strange thing is:

    I tried to do it this way: source is in the layout, so get it's geometry, then remove it from the layout, insert the target to it's place, get it's geometry then remove it - and insert the cross-fader widget to the place. It worked if the target-page has a deterministic size, but for some reason it didn't when it's (contents') size is depending on the layout (e.g. a QPushButton/QLabel with only a text doesn't work but if I set a proper fixedSize or a big-enough minimumSize to it then it works).
    What does "it doesn't work" mean (when the page-size is not deterministic): with the QPushButton example: actually it calculated some size, but the size is smaller then the real size. The cross-fader widget painted these pages sqeezed.

    The solution:

    • to the position do the same as I wrote above: get the sizes from the widgets when they are in the layout (the target is inserted, the layout is updated, get it's position then the target widget is removed). But for the sizes: get them after the widgets are removed from the layout.
      This way everything works correctly.

    Is it a bug, or did I miss something?

    I use Qt 4.7.0 (32 bit), Qt Creator 2.0.1.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Do you invalidate() the layout after adding the widgets? Calling invalidate() on the layout should cause the widget geometries to be calculated. Or did I misunderstand what you are trying to do?

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • V Offline
        V Offline
        viktor.benei
        wrote on last edited by
        #3

        I do. Actually I call these now:

        insertPageToLayout: simply inserts the page (a widget) to the _tmpCurrentLayout and calls a show() on the widget as well
        ...
        @insertPageToLayout(indexWhereToPutTheTargetWidget, targetPage);
        targetPage->show();
        targetPage->updateGeometry();
        targetPage->adjustSize();
        _tmpCurrentLayout->update();
        _tmpCurrentLayout->invalidate();
        _tmpCurrentLayout->activate();
        // QRect toGeom = to->geometry();
        QPoint targetPagePosition = targetPage->geometry().topLeft();@

        At this point the targetPagePosition is correct, but if I get the size of the widget here then the size is some smaller size than the widget's size will be. So right after this code I do this:

        @_tmpCurrentLayout->removeWidget(targetPage);
        targetPage->setParent(NULL);
        targetPage->hide(); // without this the page appears as a separate window for a second

        QRect targetPageGeom = QRect(targetPagePosition, targetPage->geometry().size());@
        

        And if I get the size here then that seems to be the real one. So far it works fine.

        NOTE: probably not all of the update/invalidate/... methods should be called, but I just didn't had the time to test the whole program whether if I leave one of them the whole program works fine everywhere. But adjustSize can't be leaved, I'm quite sure about.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          Hmmm, maybe the parent object's layout needs to be invalidated since that is what provides the size hint to the child layout? If that doesn't work could you prepare a small compileable test case that shows the problem please so that we have some code to look into? The example doesn't need to do the animation just show that the size/pos is wrong after being added to a layout and the layout being invalidated.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • V Offline
            V Offline
            viktor.benei
            wrote on last edited by
            #5

            Actually the _tmpCurrentLayout refers to the parent layout (which will actually contain the targetPage after the transition animation).

            I will prepare an example, but at this time I don't have the time for it. As soon as I can I will give you an example.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              OK no problem. Whenever you get the time. If I manage to get one put together in the meantime I'll post it here too.

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              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