Results 1 to 5 of 5

Thread: how to manipulat QStackedWidget

  1. #1
    Join Date
    Dec 2011
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default how to manipulat QStackedWidget

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how to manipulat QStackedWidget

    What did you type and what error do you exactly get?

  3. #3
    Join Date
    Dec 2011
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to manipulat QStackedWidget

    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.

    Qt Code:
    1. GUI::GUI(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::GUI)
    4. {
    5. ui->setupUi(this);
    6.  
    7.  
    8. ConnecXstatus = new QLabel(this);
    9. ui->statusBar->addPermanentWidget(ConnecXstatus);
    10. ConnecXstatus->setText("Connection Status: #### ");//later on display status&port
    11.  
    12. }
    13.  
    14. GUI::~GUI()
    15. {
    16. delete ui;
    17. }
    18.  
    19.  
    20. void GUI::on_submitcoord_clicked()
    21. {
    22. xvalue = ui->X_coord->value();
    23. yvalue = ui->Y_coord->value();
    24. }
    25.  
    26.  
    27. void GUI::on_actionQuit_triggered()
    28. {
    29. ui->actionQuit->triggered(GUI.close()); //<--still doesn't work
    30. }
    31.  
    32. void GUI::on_actionNew_Game_triggered()
    33. {
    34. ui->gamelayers->setCurrentWidget(ui->Splash_Menu);
    35. }
    36.  
    37. void GUI::on_actionHow_to_Play_triggered()
    38. {
    39. ui->gamelayers->setCurrentWidget(ui->Game_Loop);
    40. }
    41.  
    42. void GUI::on_actionAbout_triggered()
    43. {
    44. ui->gamelayers->setCurrentWidget(ui->How2PLAY);
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wuts.the.martyr; 5th December 2011 at 13:31.

  4. #4
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: how to manipulat QStackedWidget

    Nothing stops you from using setCurrentWidget() or setCurrentIndex() in window constructor.
    Simple app quit:
    Qt Code:
    1. qApp->quit();
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to manipulat QStackedWidget

    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).

    Qt Code:
    1. void GUI::on_actionQuit_triggered()
    2. {
    3. ui->actionQuit->triggered(GUI.close()); //<--still doesn't work
    4. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. void GUI::on_actionQuit_triggered()
    2. {
    3. close();
    4. // OR, as Oleg points out
    5. qApp->quit()
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTreeWidget and QStackedWidget
    By Kill3rReaper in forum Qt Programming
    Replies: 5
    Last Post: 23rd October 2011, 22:03
  2. QStackedWidget
    By sattu in forum Qt Programming
    Replies: 6
    Last Post: 28th September 2011, 13:44
  3. problem with QStackedwidget
    By psantofe in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2010, 12:41
  4. QTableWidget along with QStackedWidget
    By smiling in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2010, 12:46
  5. Help with QStackedWidget
    By onírico in forum Newbie
    Replies: 6
    Last Post: 12th November 2009, 16:34

Tags for this Thread

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.