Results 1 to 3 of 3

Thread: Show initial widget, best solution?

  1. #1
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default Show initial widget, best solution?

    In the application I'm building I need the user to input some information the first time he open the application. So in the widget that is my QMainWindow I checks if the data has been created, otherwise I need to show another widget (SetupView) for the user so he can enter the data. The rest of the application is all in MainWidget.

    In the code I'm using now the problem is that the SetupView shows up first as I set it to showMaximized but then right after I use w.showMaximized to show my MainWidget so the SetupView will not show. Can I make the SetupView show up inside MainWidget instead? I should always show the MainWidget fullscreen as this is the main window of the application right?

    I am not sure how to make a good solution out of this, but you can see the code below and maybe you find it simplier than me. I have been working with this all morning but can't figure out the best way. What is your idea? Thanks!

    In main.cpp:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MainWidget w;
    5. w.showMaximized();
    6. return a.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    In MainWidget.cpp:
    Qt Code:
    1. MainWidget::MainWidget(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. DataHolder *data = new DataHolder();
    7. if(!data->hasData())
    8. {
    9. SetupView *setupView = new SetupView();
    10. setupView->showMaximized();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Show initial widget, best solution?

    A "simple" workaround would be if you check the DataHolder in your main function before initialising you r main window. (if that is possible with your data management. One possibility could therefore be to use a singleton pattern.)

  3. The following user says thank you to Lykurg for this useful post:

    martinn (2nd March 2010)

  4. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show initial widget, best solution?

    Try something like this :
    Qt Code:
    1. MainWidget::MainWidget(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5. QTimer::singleShot( 0, this, SLOT(checkSetup()) );
    6. }
    7.  
    8. void MainWidget::checkSetup(void)
    9. {
    10. DataHolder *data = new DataHolder();
    11. if(!data->hasData())
    12. {
    13. SetupView *setupView = new SetupView();
    14. setupView->exec();
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    SetupView will be showed so fast as possible and block rest of application.

Similar Threads

  1. Can't drop a widget in designer - solution
    By heathbar82 in forum Qt Tools
    Replies: 2
    Last Post: 24th July 2012, 15:47
  2. How to show thw widget in center?
    By sudhansu in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2010, 05:51
  3. QMainWindow and custom widget doesn't show
    By Peppy in forum Qt Programming
    Replies: 9
    Last Post: 26th December 2009, 15:09
  4. How to show the widget?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 08:43
  5. How to show a window widget...
    By agent007se in forum Newbie
    Replies: 3
    Last Post: 20th July 2006, 10:42

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.