PDA

View Full Version : Dialogs in MainWindow



darkav17
13th January 2013, 15:32
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.

Boron
13th January 2013, 16:18
QWizard seems to be what you need.

d_stranz
13th January 2013, 19:10
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).

darkav17
14th January 2013, 13:07
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?

d_stranz
15th January 2013, 00:14
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:



// GamePlayView.h

#include "MainWindow.h"

class GamePlayView : public QGraphicsView
{
public:
GamePlayView( QMainWindow * pMain, QWidget * parent = 0 )
: QGraphicsView( parent )
{
// ... ui setup

connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showTablesView() ) );
}

// ...
};




// TablesView.h

#include "MainWindow.h"

class TablesView : public QGraphicsView
{
public:
TablesView ( QMainWindow * pMain, QWidget * parent = 0 )
: QGraphicsView( parent )
{
// ... ui setup

connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showGamePlayView() ) );
}

// ...
};




// MainWindow.h

#include <QMainWindow>
class QStackedWidget;

class MainWindow : public QMainWindow
{
public:
MainWindow( QWidget * parent = 0 );

public slots:
void showTablesView();
void showGamePlayView();

private:
QStackedWidget * pStack;
};




// MainWindow.cpp

#include <QStackedWidget>

#include "LoginView.h"
#include "TablesView.h"
#include "GamePlayView.h"

MainWindow::MainWindow( QWidget * parent = 0 );
: QMainWindow( parent )
{
// ... ui setup

pStack = new QStackedWidget( this );

pStack->addWidget( new LoginView( this ) );
pStack->addWidget( new TablesView( this ) );
pStack->addWidget( new GamePlayView( this ) );
setCentralWidget( pStack );

pStack->setCurrentIndex( 0 );
}

void MainWindow::showTablesView()
{
pStack->setCurrentIndex( 1 );
}

void MainWindow::showGamePlayView()
{
pStack->setCurrentIndex( 2 );
}