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. How to hide all widgets from a QVBoxLayout with spacer?
Forum Updated to NodeBB v4.3 + New Features

How to hide all widgets from a QVBoxLayout with spacer?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hey,

    I have created this GUI in Qt Creator.

    image.png

    Now I want to make some kind of edit mode. For this I want to hide the left layout of the image completely. I have tried this:

    void MainWindow::activateEditMode() const
    {
        for (int widgetNumber = 0; widgetNumber < ui->modelLayout->count(); widgetNumber++) {
            ui->modelLayout->itemAt(widgetNumber)->widget()->hide();
        }
    }
    

    However, the program crashes with a segmentation fault if the spacer is to be "hidden". What I have also read that layouts can not be hidden. What is the best way to do something like this?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Check that the returned value of widget() is not null.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        The culprit is the spacer, because it's not a widget.

        IMO, I will put all the left items in a single QWidget and hide/show it instead.

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @SGaist

          After I checked the value it works! Thanks

          @mpergand
          I have also read that on the Internet. The "morph into" function in the QT creator does exactly what you write, doesn't it? There I can also convert the layout into a QWidget.

          M 1 Reply Last reply
          0
          • ? A Former User

            @SGaist

            After I checked the value it works! Thanks

            @mpergand
            I have also read that on the Internet. The "morph into" function in the QT creator does exactly what you write, doesn't it? There I can also convert the layout into a QWidget.

            M Offline
            M Offline
            mpergand
            wrote on last edited by
            #5

            @Gabber said in How to hide all widgets from a QVBoxLayout with spacer?:

            The "morph into" function in the QT creator does exactly what you write, doesn't it? There I can also convert the layout into a QWidget.

            I have hard time to figure out how to convert (morph?) a layout to a widget.

            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