[Solved] How to hide and show a mainwindow?
-
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?
-
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.
-
@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.
-
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.
-
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.
-
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.
-
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) -
so you have solved it?
if so, please add [Solved] in your title -
Done :)
-
Stripping down a problem to it's essential is a good way of discovering solutions, isn't it?
Have fun Qt programming
-
sorry but I can`t download the zip file you,Eddy,have posted ,if possible please paste the required code just right here!!!,Plz ;)
-
I have posted the example zip file before 1 year so now i quess i dont have it anymore..
what is exactly your problem?
[quote author="amin" date="1345330155"]sorry but I can`t download the zip file you,Eddy,have posted ,if possible please paste the required code just right here!!!,Plz ;)[/quote]
-
tnx a lot that u answered,hopefully i myself made it out, again tanQ by the way.. ;)