PDA

View Full Version : Showing QMainWindow without showing a child QWidget



discostu
4th March 2007, 06:06
I have a QWidget which I want to remain hidden until the user presses a shortcut. The shortcut works fine, but I don't want the QWidget to show up when the application starts up. The QWidget is added in the MyMainWindow's constructor. In my main function an instance of my subclass QMainWindow is created and then mymainwindow.show(); is called. When this is called all the child widgets are shown.

Any way to do this other than waiting to create the widget til after mymainwindow.show() is called.

aamer4yu
4th March 2007, 06:16
You can create the widget in window's constructor. But set it as hidden using void QWidget::hide ()
Then when u press a button, u can show the widget :)

discostu
4th March 2007, 06:40
You can create the widget in window's constructor. But set it as hidden using void QWidget::hide ()
Then when u press a button, u can show the widget :)

I figured out a solution. The widget was a QDialog. I changed it to QWidget and that fixed the problem. I was doing what you suggested, aamer4yu, but it only works with the QWidget, not the QDialog. I wonder though, can a QDialog be hidden at startup with this method? It wasn't working for me.

Thanks for your quick response.
Stu

fullmetalcoder
4th March 2007, 10:03
I wonder though, can a QDialog (http://doc.trolltech.com/latest/qdialog.html) be hidden at startup with this method? It wasn't working for me.
It should work except maybe if the dialog is shown through exec()... If it doesn't you can always reimplement the showEvent() method and reject the event until you've been notified that GUI has been fully set up.