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. Hide All function?
Forum Updated to NodeBB v4.3 + New Features

Hide All function?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 7.2k Views 1 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.
  • R Offline
    R Offline
    roosaw
    wrote on last edited by
    #1

    Hey,
    Is there is a function which hide all widgets on window? All labels, all buttons, all text fields, all LCDNumbers. All this stuff. I wanna clear my window and show only background. Is there is a function to do it or i have to do it myself?

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      I don't think that there is that functionality in Qt, but one idea is to iterate over the "QObjectList":http://doc.qt.nokia.com/latest/qobject.html#children that contains the children of that QWidget and call hide on them.
      This approach will hide the children that are windows too, so maybe someone comes with a better idea.

      Also if you use a QMainWindow you can change the centralWidget.

      LE: tell us what are you trying to achieve, why are you trying to hide everything? This will help everybody give better advices

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • R Offline
        R Offline
        roosaw
        wrote on last edited by
        #3

        I try to write a game and if player win or lose I wanna add MessageBox with "You win, yeah" or "Oh noes! you lose" and clear all the area.

        Maybe without all objects it will look better than with it?:)

        Or if there is no that function I'll cover the whole screen (with QPaint or something) with black or grey color and the effect will be the same, i think.

        But, the best way is to hide all, i think.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kxyu
          wrote on last edited by
          #4

          well, all these widgets have common parent, haven't they? so you can iterate over widget->children() and set all of them invisible

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ivan
            wrote on last edited by
            #5

            Or just hide the parent widget :) (if the parent is a main window, you can always add a frame to it that will hold all the widgets)

            Ivan Čukić | ivan.cukic(at)kde.org | KDE e.V.
            Qt Ambassador (from the old Nokia days)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mohsen
              wrote on last edited by
              #6

              if you want to hide all objects use
              @foreach(QWidget obj, findChildren<QWidget>())
              {
              obj->setVisible(false);
              }@

              even it's possible to limit the control to only one type of object for example by using QPushButton instead of QWidget.

              But i don't recommend it for your application.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mohsen
                wrote on last edited by
                #7

                doesn't it better to use QML for creating your game?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  I would use a "QStackedWidget":http://doc.trolltech.com/4.7/qstackedwidget.html with one page containing the actual UI and an empty page to be shown when your message box is running.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    [quote author="mohsen" date="1296156799"]if you want to hide all objects use
                    @foreach(QWidget obj, findChildren<QWidget>())
                    {
                    obj->setVisible(false);
                    }@

                    even it's possible to limit the control to only one type of object for example by using QPushButton instead of QWidget.
                    [/quote]

                    This works for the hiding part, but gives you problems when the widgets should be shown again. Many widgets contain subwidgets (eg. a list view in a combo box) which are found by findChildren() too and may be erroneously shown when setVisible(true) with the above code.

                    If you need such functionality put all the actual UI into a single container widget and hide this one or use a QStackedWidget and switch pages.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    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