PDA

View Full Version : how to manipulat QStackedWidget



wuts.the.martyr
5th December 2011, 12:30
hi all, I have built a sweet game ui in Qt Creator, but I keep hitting roadblocks with the code, since I am unable to do some things manually. This may just be a short coming on my part. For instance when I try to use QStackedWidget type slots/signals i get alot of errors when i manually type them in, since they are not included in the Qt Designer. anywho, i found the class referrence page and I was wondering do I need to create the class it self, or shouldn't i just be able to include the QStackedWidget class at the top of my mainwindow.cpp. Should I be creating an instance of QStackedWidget? It should already be doing this but I dont see the code for it anywhere in Qt Creator.

Thanks

wuts

Lykurg
5th December 2011, 12:38
What did you type and what error do you exactly get?

wuts.the.martyr
5th December 2011, 13:21
well i got it to finally switch between pages, but I would like it to always open a certain page when you run the app

is there a script I can run to set StackedWidget Index on app startup? I have attached my current mainwindow.cpp code, I would also like to fix my actionQuit, since I can only get it to work currently from the signal/slots tool in the Designer mode, but I would rather have it all set here.


GUI::GUI(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::GUI)
{
ui->setupUi(this);


ConnecXstatus = new QLabel(this);
ui->statusBar->addPermanentWidget(ConnecXstatus);
ConnecXstatus->setText("Connection Status: #### ");//later on display status&port

}

GUI::~GUI()
{
delete ui;
}


void GUI::on_submitcoord_clicked()
{
xvalue = ui->X_coord->value();
yvalue = ui->Y_coord->value();
}


void GUI::on_actionQuit_triggered()
{
ui->actionQuit->triggered(GUI.close()); //<--still doesn't work
}

void GUI::on_actionNew_Game_triggered()
{
ui->gamelayers->setCurrentWidget(ui->Splash_Menu);
}

void GUI::on_actionHow_to_Play_triggered()
{
ui->gamelayers->setCurrentWidget(ui->Game_Loop);
}

void GUI::on_actionAbout_triggered()
{
ui->gamelayers->setCurrentWidget(ui->How2PLAY);
}

Oleg
5th December 2011, 16:31
Nothing stops you from using setCurrentWidget() or setCurrentIndex() in window constructor.
Simple app quit:


qApp->quit();

ChrisW67
5th December 2011, 21:21
well i got it to finally switch between pages, but I would like it to always open a certain page when you run the app
The code you wrote to change the current page is exactly what you use to set the starting page (in your constructor or elsewhere in your initialisation).


void GUI::on_actionQuit_triggered()
{
ui->actionQuit->triggered(GUI.close()); //<--still doesn't work
}

Why did you think it would? You are calling the automatically generated code for a signal from within a slot (automatically) attached to that same signal. I am surprised your program does not implode ;)

Your slot code needs to call something to either close the current QWidget (if it is the last top level window then this usually terminates the app) or explicitly quitting your app.


void GUI::on_actionQuit_triggered()
{
close();
// OR, as Oleg points out
qApp->quit()
}