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"
{
public:
{
// ... ui setup
connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showTablesView() ) );
}
// ...
};
// 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() ) );
}
// ...
};
To copy to clipboard, switch view to plain text mode
// TablesView.h
#include "MainWindow.h"
{
public:
{
// ... ui setup
connect( ui->switchViewButton, SIGNAL( clicked() ), pMain, SLOT( showGamePlayView() ) );
}
// ...
};
// 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() ) );
}
// ...
};
To copy to clipboard, switch view to plain text mode
// MainWindow.h
#include <QMainWindow>
{
public:
MainWindow
( QWidget * parent
= 0 );
public slots:
void showTablesView();
void showGamePlayView();
private:
};
// MainWindow.h
#include <QMainWindow>
class QStackedWidget;
class MainWindow : public QMainWindow
{
public:
MainWindow( QWidget * parent = 0 );
public slots:
void showTablesView();
void showGamePlayView();
private:
QStackedWidget * pStack;
};
To copy to clipboard, switch view to plain text mode
// MainWindow.cpp
#include <QStackedWidget>
#include "LoginView.h"
#include "TablesView.h"
#include "GamePlayView.h"
MainWindow
::MainWindow( QWidget * parent
= 0 );
{
// ... ui setup
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 );
}
// 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 );
}
To copy to clipboard, switch view to plain text mode
Bookmarks