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.
  • A Offline
    A Offline
    Andy314
    wrote on 11 Jun 2015, 10:07 last edited by Andy314 6 Nov 2015, 18:08
    #1

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

    P C 2 Replies Last reply 12 Jun 2015, 05:05
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Jun 2015, 23:03 last edited by SGaist 6 Dec 2015, 07:30
      #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
      • A Andy314
        11 Jun 2015, 10:07

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

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 12 Jun 2015, 05:05 last edited by
        #3

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

        157

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Jun 2015, 07:31 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
          • A Offline
            A Offline
            Andy314
            wrote on 12 Jun 2015, 11:28 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Jun 2015, 23:06 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
              • A Andy314
                11 Jun 2015, 10:07

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

                C Offline
                C Offline
                CP71
                wrote on 18 Mar 2019, 12:21 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