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. [Solved] How to hide and show a mainwindow?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to hide and show a mainwindow?

Scheduled Pinned Locked Moved General and Desktop
22 Posts 8 Posters 49.9k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    So a dialog can be hide with hide(); and can been shown with show();
    But what about if it is not a dialog but the mainwindow?
    hide(); doesn't hide my mainwindow....

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NarutoUzumakis
      wrote on last edited by
      #2

      why would you want to hide your mainwindow at all??can you be more specific

      1 Reply Last reply
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #3

        I just tried it out, hide() hides my MainWindow. Are you reimplementing the event() method?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sfilippidis
          wrote on last edited by
          #4

          [quote author="Leon" date="1307885217"]So a dialog can be hide with hide(); and can been shown with show();
          But what about if it is not a dialog but the mainwindow?
          hide(); doesn't hide my mainwindow....[/quote]

          How (eg: by using a push button?) and why do you plan to hide the main window? How and why do you plan to re-display the main window?

          https://www.filippidis.name/

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            My app pops app a dialog and from there you can take a screenshot. And it has the ability to hide the dialog and after the screenshot has been take show it again. But i also want to hide the mainwindow..

            So at the mainwindow hide(); doesn't hide the window.. What's wrong?

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Using hide() should work on QMainwindow.

              I just tested it to be sure since i never needed this.

              So there must be something else going on
              I suggest you make a minimal compilable example that reproduces your problem or show us the relevant code.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                It must be a bug of Ubuntu 11.04 again...

                As for an example... Putting hide(); at the constructor of the mainwindow.cpp won't hide the window...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sfilippidis
                  wrote on last edited by
                  #8

                  [quote author="Leon" date="1307951240"]My app pops app a dialog and from there you can take a screenshot. And it has the ability to hide the dialog and after the screenshot has been take show it again. But i also want to hide the mainwindow..

                  So at the mainwindow hide(); doesn't hide the window.. What's wrong?[/quote]

                  Just a guess: maybe you are calling hide() method/function of the wrong object (ie: not for the main window) by accident? Check it! ;-)

                  https://www.filippidis.name/

                  1 Reply Last reply
                  0
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #9

                    try to use hide in your main()

                    there you make an instance of your mainwindow class and you hide that instance.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jim_kaiser
                      wrote on last edited by
                      #10

                      bq. As for an example… Putting hide(); at the constructor of the mainwindow.cpp won’t hide the window…

                      I suspected that's what you were doing. I don't think that should be expected to work. Although, the QMainWindow is constructed by then, i think you should try it after the construction of the MainWindow object is complete. Also, are you saying that the main window is shown without calling show()? Because you call hide() in the MainWindow constructor, where do you call show?

                      1 Reply Last reply
                      0
                      • EddyE Offline
                        EddyE Offline
                        Eddy
                        wrote on last edited by
                        #11

                        could you make an new widget based Qt project, choose a QMainwindow as class and use the following code in your main.

                        like this :
                        @int main(int argc, char *argv[])
                        {
                        QApplication a(argc, argv);
                        MainWindow w;
                        w.show();

                        QTimer timer;
                        
                        timer.singleShot(1000, &w, SLOT(hide()));
                        
                        return a.exec();
                        

                        }@

                        normally this should work unless you have other issues.

                        Qt Certified Specialist
                        www.edalsolutions.be

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #12

                          @jim_kaiser
                          it is possible to use hide() in the constructor of a QMainwindow class.
                          I tested it using a singleshot timer too.

                          you're right asking where Leon uses his show() function, probably this one is called after the hide() function.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            jim_kaiser
                            wrote on last edited by
                            #13

                            @eddy

                            Thanks for the clarification about the hide() in the constructor. Assumed there might be events from the desktop which the main windows reacts to after the construction and just thought its a bit iffy.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #14

                              Hi,

                              by default each widget is hiodden, unless it has a visible parent. So hide in the constructorn is not needed. But mostly, the main contains a show call, remove that and it is hidden.

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              1 Reply Last reply
                              0
                              • EddyE Offline
                                EddyE Offline
                                Eddy
                                wrote on last edited by
                                #15

                                Hi Gerolf,

                                You're right it's hidden unless you show it first.

                                But what Leon wants is to use a mainwindow and click a button to hide it. Hiding seems not to work on his system. That's why i suggested to use a minimal working example because we don't have code to look at.

                                Qt Certified Specialist
                                www.edalsolutions.be

                                1 Reply Last reply
                                0
                                • L Offline
                                  L Offline
                                  Leon
                                  wrote on last edited by
                                  #16

                                  Ok so probably it was wrong to put hide(); at the constructor.. Putting it in a void function will work..
                                  I made an example that hides both the dialog and the mainwindow :) ("Link":http://dl.dropbox.com/u/11379868/hideExample.zip)

                                  1 Reply Last reply
                                  0
                                  • EddyE Offline
                                    EddyE Offline
                                    Eddy
                                    wrote on last edited by
                                    #17

                                    so you have solved it?
                                    if so, please add [Solved] in your title

                                    Qt Certified Specialist
                                    www.edalsolutions.be

                                    1 Reply Last reply
                                    0
                                    • L Offline
                                      L Offline
                                      Leon
                                      wrote on last edited by
                                      #18

                                      Done :)

                                      1 Reply Last reply
                                      0
                                      • EddyE Offline
                                        EddyE Offline
                                        Eddy
                                        wrote on last edited by
                                        #19

                                        Stripping down a problem to it's essential is a good way of discovering solutions, isn't it?

                                        Have fun Qt programming

                                        Qt Certified Specialist
                                        www.edalsolutions.be

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          amin
                                          wrote on last edited by
                                          #20

                                          sorry but I can`t download the zip file you,Eddy,have posted ,if possible please paste the required code just right here!!!,Plz ;)

                                          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