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. Widget setVisible(false) without layout changing ?
Forum Updated to NodeBB v4.3 + New Features

Widget setVisible(false) without layout changing ?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 6.2k Views 4 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?

    p3c0P CP71C 2 Replies Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      I'm not sure I'm following correctly, what would you like to achieve ?

      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
      0
      • Andy314A Andy314

        Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?

        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        @Andy314 I guess you will need to insert an empty QWidget or a QSpacerItem.

        157

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

          After getting some sleep… You could use a QStackedWidget/Layout with an empty widget in. When you want to "hide" your main widget, just change the current widget of the stack.

          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
          0
          • Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by
            #5

            Sometimes it is more logical to hide a widget instead of disabling it.
            (Button funktion makes in the current state no sense - a info text is not needed, etc.)
            But I want avoid the resizing/moving of the other widgets, so that the dialog stays stable.
            (Widget keeps the same sizeHint but draw itself as invisible.)
            I tested:
            The trick with the empy widget and an invisible widget in it works very well.
            QStackedWidget must work too.

            Is there a special page, where some common tricks for the Qt GUI designing are explained ?

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

              Not that I know of but the wiki is pretty big (and currently in a cleanup phase)

              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
              0
              • Andy314A Andy314

                Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?

                CP71C Offline
                CP71C Offline
                CP71
                wrote on last edited by
                #7

                @Andy314
                Hi
                Sorry if I use this post for an updating,
                I want to do same thing in Qt 4.X and I have found this post:

                https://stackoverflow.com/questions/1874426/hiding-qt-widget-and-keeping-widget-space

                The tip is using QsizePolicy, for example:

                QSizePolicy sp_retain = ui->label_3->sizePolicy();
                sp_retain.setRetainSizeWhenHidden(true);
                ui->label_3->setSizePolicy(sp_retain);
                ui→label_3→hide();
                

                Unfortunately is not possible to use in Qt 4 but only in Qt5 :(

                Regards

                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