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. Easiest way to hide widget and spacing in QLayout
Qt 6.11 is out! See what's new in the release blog

Easiest way to hide widget and spacing in QLayout

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.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.
  • UnickU Offline
    UnickU Offline
    Unick
    wrote on last edited by
    #1

    Hello.

    I have lauout with several buttons.

        auto buttonsLayout = new QHBoxLayout(buttonsWidget);
        button1 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button2 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button3 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    
        button4 = new QPushButton(buttonsWidget);
        buttonsLayout->addSpacing(24);
    

    And i want to hide button3. After that, i will have 2 spacers between button2 and button4. Is there the method to hide button3 with spacing simultaneously? What is the easiest way? I know i can find this space and hide it manually, but i hope there is exists automatically method.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      since all the spacing is the same just remove all the buttonsLayout->addSpacing(24); and call buttonsLayout->setSpacing(24); just once. it will fix everything

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • UnickU Offline
        UnickU Offline
        Unick
        wrote on last edited by
        #3

        Thanks, it works.

        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