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. Add a widget to a horizontal box layout without moving everything else in the layout
Forum Updated to NodeBB v4.3 + New Features

Add a widget to a horizontal box layout without moving everything else in the layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 810 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.
  • V Offline
    V Offline
    VogelPapaFinn
    wrote on 11 Jul 2022, 20:46 last edited by
    #1

    Hello!
    I want a button to popup a (self-created) widget on the left side. At the moment my button is in a horizontal layout with three labels. I want my menu to be in that layout so it gets resized depending on the resolution of the window. But when I hide/show my menu it frees it space and everything in the layout moves because the available space changes.
    Is there a way to fix this?
    Thanks!

    Note:
    I cant use QMenu due to its limitated styling (top-level widget).

    G 1 Reply Last reply 12 Jul 2022, 18:05
    0
    • V VogelPapaFinn
      11 Jul 2022, 20:46

      Hello!
      I want a button to popup a (self-created) widget on the left side. At the moment my button is in a horizontal layout with three labels. I want my menu to be in that layout so it gets resized depending on the resolution of the window. But when I hide/show my menu it frees it space and everything in the layout moves because the available space changes.
      Is there a way to fix this?
      Thanks!

      Note:
      I cant use QMenu due to its limitated styling (top-level widget).

      G Offline
      G Offline
      Gojir4
      wrote on 12 Jul 2022, 18:05 last edited by
      #2

      @VogelPapaFinn Hi, did you try to use a stretch in your layout ?
      QLayout::addStretch() or Horizontal Spacer in Designer. It should take the empty space when you hide your widget.

      V 1 Reply Last reply 12 Jul 2022, 20:55
      0
      • G Gojir4
        12 Jul 2022, 18:05

        @VogelPapaFinn Hi, did you try to use a stretch in your layout ?
        QLayout::addStretch() or Horizontal Spacer in Designer. It should take the empty space when you hide your widget.

        V Offline
        V Offline
        VogelPapaFinn
        wrote on 12 Jul 2022, 20:55 last edited by
        #3

        @Gojir4 Hi!
        QGridLayout::setColumnStretch() doesnt work at all and a spacer pushes everything else to the left corner ._.

        G M 2 Replies Last reply 12 Jul 2022, 21:04
        0
        • V VogelPapaFinn
          12 Jul 2022, 20:55

          @Gojir4 Hi!
          QGridLayout::setColumnStretch() doesnt work at all and a spacer pushes everything else to the left corner ._.

          G Offline
          G Offline
          Gojir4
          wrote on 12 Jul 2022, 21:04 last edited by
          #4

          @VogelPapaFinn Did you set the stretch on first column ?
          can't you put the spacer at the left so it pushes everything on the right ?

          1 Reply Last reply
          0
          • V VogelPapaFinn
            12 Jul 2022, 20:55

            @Gojir4 Hi!
            QGridLayout::setColumnStretch() doesnt work at all and a spacer pushes everything else to the left corner ._.

            M Offline
            M Offline
            mpergand
            wrote on 12 Jul 2022, 21:06 last edited by mpergand 7 Dec 2022, 21:07
            #5

            @VogelPapaFinn

            First add an horizontal layout then add a spacer and your 'menu'

            V 1 Reply Last reply 12 Jul 2022, 21:19
            0
            • M mpergand
              12 Jul 2022, 21:06

              @VogelPapaFinn

              First add an horizontal layout then add a spacer and your 'menu'

              V Offline
              V Offline
              VogelPapaFinn
              wrote on 12 Jul 2022, 21:19 last edited by VogelPapaFinn 7 Dec 2022, 21:20
              #6

              @mpergand theoretically it would do the same, wouldnt it?
              I found another solution: As parent I choose the parent of the vertical layout my button is in. Then I just set it to the position of the button. But now I encounter a new problem: How do I override the resize event of the window? When I resize the window my menu stays at the same position in the middle of the screen.

              G 1 Reply Last reply 12 Jul 2022, 21:39
              0
              • V VogelPapaFinn
                12 Jul 2022, 21:19

                @mpergand theoretically it would do the same, wouldnt it?
                I found another solution: As parent I choose the parent of the vertical layout my button is in. Then I just set it to the position of the button. But now I encounter a new problem: How do I override the resize event of the window? When I resize the window my menu stays at the same position in the middle of the screen.

                G Offline
                G Offline
                Gojir4
                wrote on 12 Jul 2022, 21:39 last edited by
                #7

                @VogelPapaFinn You should use a layout for your main window. Don't position your widgets manually.

                1 Reply Last reply
                0

                1/7

                11 Jul 2022, 20:46

                • Login

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