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. Strange behavior of widgets in QVBoxLayout
QtWS25 Last Chance

Strange behavior of widgets in QVBoxLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
positionlayoutqspacer
10 Posts 4 Posters 2.4k 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.
  • M Offline
    M Offline
    MasterBLB
    wrote on 11 Dec 2018, 08:32 last edited by MasterBLB
    #1

    Hey Qt devs

    I've encountered a strange issue - though I've added a vertical QSpacerItem the space is not fully consumed by it.
    1st, a picture:
    alt text
    Pic1
    legend:
    red rectangle - widget the question is about
    green rectangle - parent QVboxLayout which contains widget(s) with the above layout, and a spacer item
    blue elements - QSpacerItem

    I've adde to the widget illustrated by these grey tables with white borders own QVBoxLayout:

       inventoryLayout = new QVBoxLayout;
       inventoryLayout->setDirection(QVBoxLayout::TopToBottom);
       inventoryLayout->setContentsMargins(0, 0, 0, 0);
       inventoryLayout->setSpacing(0);
       setLayout(inventoryLayout);
    

    after that I add widgets into the layout like this:

        for (int cnt = 0; cnt < 6; cnt++)
        {
            InventoryItemWidget *item = new InventoryItemWidget(this);
            inventoryLayout->addWidget(item);
        }    
        inventoryLayout->addStretch();
    

    this seems to work correctly, these InventoryItemWidgets are pushed towards top edge of InventoryWidget.
    Strange things start to happen when I try to stretch the window vertically - it looks like the spacer created by inventoryLayout->addStretch() went from the red layout into the green layout, and places between "Strip stuff" button and InventoryWidget. Here is screenshot how it looks like:
    alt text
    Pic2
    If I will remove that line the widgets behave correctly, though these M Laser objects are of course not aligned to the top edge of inventory.
    What detail about layouts/widgets I'm missing?

    Definitions in the .ui files:
    alt text
    alt text

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MasterBLB
      wrote on 16 Dec 2018, 11:04 last edited by
      #2

      Hmm no one have a clue?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 16 Dec 2018, 11:08 last edited by
        #3

        Can you share your images & workable example somewhere ? Images seems to be missing.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MasterBLB
          wrote on 16 Dec 2018, 12:41 last edited by
          #4

          Strange, I can see them o.O

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dheerendra
            Qt Champions 2022
            wrote on 16 Dec 2018, 12:48 last edited by
            #5

            At least I am not able see the images. If u can share it and also workable code to check it will help us to help you.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MasterBLB
              wrote on 16 Dec 2018, 13:56 last edited by MasterBLB
              #6

              Hmm, edit feature works strane, so I'll add the pictures here. Uploaded to postimage.org, so should be fine this time
              Pic1
              Pic2
              Pic3
              Pic4

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MasterBLB
                wrote on 21 Dec 2018, 06:25 last edited by
                #7

                Oh my, seriously not even a slightest clue?

                J M 2 Replies Last reply 21 Dec 2018, 07:43
                0
                • M MasterBLB
                  21 Dec 2018, 06:25

                  Oh my, seriously not even a slightest clue?

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 21 Dec 2018, 07:43 last edited by
                  #8

                  @MasterBLB

                  soryy can't help here much,

                  But let me ask, how are you managing the position of your 5 vertical layouts ?

                  Are they also managed by a QLayout ? QHBoxLayout seems appropriate.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • M MasterBLB
                    21 Dec 2018, 06:25

                    Oh my, seriously not even a slightest clue?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 21 Dec 2018, 08:30 last edited by
                    #9

                    @MasterBLB
                    Hi
                    I read it a few times but it could be anything.
                    My first guess was that you insert the "Right arm" "HEAD" etc after the spacer.
                    Like its already in UI file and you just use layout->addwidget so it comes after spacer.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MasterBLB
                      wrote on 21 Dec 2018, 08:43 last edited by
                      #10

                      It is as follows:
                      Pic 3 with these long spacers contains complex widgets MechPartWidget presented in pic 4. You can see a tiny selection above the 2nd vertical spacer
                      Then, in MechPartWidget there are no layouts/widgets with vertical horizontal policy set to expanding.
                      Next, in the MechPartWidget there is a custom widget InventoryWidget. I tried to add QVBoxLayout to it, several widgets, and then a vertical spacer - and I expect this own-added layout would be honoured only inside boundaries of InventoryWidget, yet it isn't.

                      1 Reply Last reply
                      0

                      10/10

                      21 Dec 2018, 08:43

                      • Login

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