Results 1 to 5 of 5

Thread: Dialogs in MainWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Dialogs in MainWindow

    Is it possible to make one main window and many dialogs like pages in stackedwidgets inside this window?
    For example: Run app, in main window we have login form and button for log in. When we push button for log in, in main window login form disappear and we have next form with text and buttons. When we one push button we are going to next 'page' with another text and buttons. In every step we can log out and come back to first 'page'.

    I tried this with stacked widgets but when we go to next page and then come back, every change that we make on the previous page is still there and i dont know how to 'refresh' that page.

    In the other way i tried to do just 3 windows and from 1 invoke 2 and from 2 invoke 3 but i dont know how to do like that: we run 1 window, and from this one we close that window and open second one when we click button like in first example with login, we close second window and opens third and then we want to close third window when we push log out button and open first window. I now how to do: 1window->2window->3window but dont know how to do like this 1window->pushbutton login(close 1 window open 2window)->2window->push button(close 2window open 3window)->3window->push button back/logout(close 3window open 2window/1window).

    So, in short way: i cant invoke 1/2 window from 3window even if i include headers from this windows.

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dialogs in MainWindow

    QWizard seems to be what you need.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dialogs in MainWindow

    Even if you use QWizard, you still have to create a class or other data structure that will hold the information the user is entering as they go from page to page.

    If you want the action of going back to the previous page to restore the default values (not the values as changed by the user), then you either need to keep two copies of the data structure (one with defaults, one with edited values), and swap them as required, or respond to the back action by resetting the values to the defaults..

    I think the idea of clicking a Back button and seeing that all the values I just spent 10 minutes editing are gone would really annoy me. A better design would be to have a button on each page that says "Reset" or something like that, and only replace the user's values with the defaults when they ask you to (by clicking Reset).

  4. #4
    Join Date
    Jan 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dialogs in MainWindow

    Hmm I dont know that you understand what I want to do. So I will tell everything:
    It's poker network game. First when we launch app we have Login/Register window which disappear when we log in.
    Then we see second window with tables which you can join, chat and something like list of online users. When we join to one of the tables then we see window with game, but i dont want to open everytime new window and close that previous(second one) but show game in this main window with tables.
    How to do something like this? As I said i tried with qstackedwidgets but it's not good idea, so I think that qwizard is something similar and does not meet requirements. I tried to do it that we have 3 windows(but it looks bad), one with login, second with tables and third with gameplay but there I have a problem that when i close second window and open third(when click join button) and then want to leave game and come back to tables view I can't invoke second window from third even if I include headers to second window. If there is no possibility to do it in one window, so how to do it with this three?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dialogs in MainWindow

    You *can* do this easily with a stack widget. The whole purpose of a stack widget is to allow you to display multiple windows, one at a time, in the same space.

    If you want to be able to switch back and forth between the gameplay view and tables view, simply put a button on each of those pages that the user can click. On the tables view, it says "Show game" and on the gameplay view it says "Show tables" or something like that. In the main window, add slots that connect the clicked() signals from these buttons to switch the stack to the proper page, something like this:

    Qt Code:
    1. // GamePlayView.h
    2.  
    3. #include "MainWindow.h"
    4.  
    5. class GamePlayView : public QGraphicsView
    6. {
    7. public:
    8. GamePlayView( QMainWindow * pMain, QWidget * parent = 0 )
    9. : QGraphicsView( parent )
    10. {
    11. // ... ui setup
    12.  
    13. connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showTablesView() ) );
    14. }
    15.  
    16. // ...
    17. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // TablesView.h
    2.  
    3. #include "MainWindow.h"
    4.  
    5. class TablesView : public QGraphicsView
    6. {
    7. public:
    8. TablesView ( QMainWindow * pMain, QWidget * parent = 0 )
    9. : QGraphicsView( parent )
    10. {
    11. // ... ui setup
    12.  
    13. connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showGamePlayView() ) );
    14. }
    15.  
    16. // ...
    17. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // MainWindow.h
    2.  
    3. #include <QMainWindow>
    4.  
    5. class MainWindow : public QMainWindow
    6. {
    7. public:
    8. MainWindow( QWidget * parent = 0 );
    9.  
    10. public slots:
    11. void showTablesView();
    12. void showGamePlayView();
    13.  
    14. private:
    15. QStackedWidget * pStack;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // MainWindow.cpp
    2.  
    3. #include <QStackedWidget>
    4.  
    5. #include "LoginView.h"
    6. #include "TablesView.h"
    7. #include "GamePlayView.h"
    8.  
    9. MainWindow::MainWindow( QWidget * parent = 0 );
    10. : QMainWindow( parent )
    11. {
    12. // ... ui setup
    13.  
    14. pStack = new QStackedWidget( this );
    15.  
    16. pStack->addWidget( new LoginView( this ) );
    17. pStack->addWidget( new TablesView( this ) );
    18. pStack->addWidget( new GamePlayView( this ) );
    19. setCentralWidget( pStack );
    20.  
    21. pStack->setCurrentIndex( 0 );
    22. }
    23.  
    24. void MainWindow::showTablesView()
    25. {
    26. pStack->setCurrentIndex( 1 );
    27. }
    28.  
    29. void MainWindow::showGamePlayView()
    30. {
    31. pStack->setCurrentIndex( 2 );
    32. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 6th November 2011, 09:22
  2. Replies: 1
    Last Post: 12th April 2011, 09:53
  3. Closing all of the mainWindow's child dialogs
    By JPNaude in forum Qt Programming
    Replies: 4
    Last Post: 2nd October 2008, 13:18
  4. MainWindow+Dialogs
    By fruzzo in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2008, 08:52
  5. Skinned dialogs
    By Lele in forum Qt Programming
    Replies: 24
    Last Post: 9th August 2007, 08:43

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
  •  
Qt is a trademark of The Qt Company.