Results 1 to 4 of 4

Thread: Showing QMainWindow without showing a child QWidget

  1. #1
    Join Date
    Mar 2007
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Showing QMainWindow without showing a child QWidget

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Showing QMainWindow without showing a child QWidget

    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

  3. #3
    Join Date
    Mar 2007
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Showing QMainWindow without showing a child QWidget

    Quote Originally Posted by aamer4yu View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Showing QMainWindow without showing a child QWidget

    Quote Originally Posted by discostu View Post
    I wonder though, can a QDialog 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.
    Current Qt projects : QCodeEdit, RotiDeCode

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.