Results 1 to 3 of 3

Thread: how to show and hide frames?

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to show and hide frames?

    Hello,

    I would like to present a popup at the beginning of my program, which let the user chose between 2 modes.
    If the user makes his choice, then a new window shall be opened. Unfortunately, bot the popup and another window disappear after clicking on one of the pushbuttons. Can you tell me what is the reason and how to deal with this problem (see my code below)?
    Thank you

    best regards,

    Vitali

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QMessageBox>
    4. #include <mainframe.h>
    5. #include "dialog_start.h"
    6. #include "OscillationGRN.h"
    7.  
    8. int main(int argc, char **argv)
    9. {
    10.  
    11. QApplication app(argc, argv);
    12.  
    13. // first appears a popup, which will offer to the user 2 different kinds of problems
    14. QMessageBox msgBox;
    15. QPushButton *OscillationButton = msgBox.addButton("Sustained Oscillation", QMessageBox::ActionRole);
    16. QPushButton *BenchmarkButton = msgBox.addButton("constrained Problems",QMessageBox::ActionRole);
    17.  
    18. msgBox.exec();
    19.  
    20. if(msgBox.clickedButton() == BenchmarkButton){ // if the user decide to cope with optimization of constrained benchmark problems
    21.  
    22. mainFrame mainWind;
    23.  
    24. // execute the initialization dialog
    25. dialogStart start(0, &mainWind);
    26. start.show(); // the mainWindow will be opened after the user click on START button within dialogStart
    27. msgBox.hide();
    28. }
    29. else if(msgBox.clickedButton() == OscillationButton){ // if the user decide to cope with generation of oscillation by means of Gene Regulatory Networks
    30. OscillationGRN evoGRN;
    31. evoGRN.show();
    32. msgBox.hide();
    33. }
    34. return app.exec();
    35.  
    36. exit(EXIT_SUCCESS);
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 

  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: how to show and hide frames?

    Probably because you are declaring the windows inside the if else condition.
    mainFrame mainWind; and OscillationGRN evoGRN;
    Try declaring them above the if condition on a larger scope

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

    rambo83 (6th January 2010)

  4. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to show and hide frames?

    Yes, you are right, aamer4yu. Thank you

    Now it works with the following code:

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QMessageBox>
    4. #include <mainframe.h>
    5. #include "dialog_start.h"
    6. #include "OscillationGRN.h"
    7. #include <iostream>
    8.  
    9. int main(int argc, char **argv)
    10. {
    11.  
    12. QApplication app(argc, argv);
    13.  
    14. // first appears a popup, which will offer to the user 2 different kinds of problems
    15. QMessageBox msgBox;
    16. msgBox.setIcon(QMessageBox::Question);
    17. msgBox.setText("Which one of the optimization problems do you want to execute?");
    18. msgBox.setInformativeText("Make your choice by clicking on button.");
    19. QPushButton *OscillationButton = msgBox.addButton("Sustained Oscillation", QMessageBox::ActionRole);
    20. QPushButton *BenchmarkButton = msgBox.addButton("Constrained Problems",QMessageBox::NoRole);
    21.  
    22. msgBox.exec();
    23.  
    24. mainFrame mainWind; // build Main Window
    25.  
    26. dialogStart start(0, &mainWind); // build Initialization window
    27.  
    28. OscillationGRN evoGRN; // build OscillationGRN window
    29.  
    30. if(msgBox.clickedButton() == BenchmarkButton){ // if the user decide to cope with optimization of constrained benchmark problems
    31.  
    32. start.show(); // the mainWindow will be opened after the user click on START button within dialogStart
    33.  
    34. }
    35. else if(msgBox.clickedButton() == OscillationButton){ // if the user decide to cope with generation of oscillation by means of Gene Regulatory Networks
    36.  
    37. evoGRN.show();
    38.  
    39. }
    40. return app.exec();
    41.  
    42. exit(EXIT_SUCCESS);
    43.  
    44. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Hide and Show problem in master layout
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 16:04
  2. Hide and Show QMenu
    By febil in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 09:31
  3. hide from taskbar but show to ALT-TAB
    By musikit in forum Qt Programming
    Replies: 0
    Last Post: 15th August 2008, 16:14
  4. Show or hide a form
    By Gayathri in forum Newbie
    Replies: 11
    Last Post: 17th November 2006, 12:39
  5. Show/hide part of dialog with resizing.
    By Spockmeat in forum Qt Tools
    Replies: 6
    Last Post: 7th June 2006, 08:22

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.