Results 1 to 7 of 7

Thread: QStackedWidget

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QStackedWidget

    Hi Everyone,

    To my mainwindow, I have added a StackedWidget. In the StackedWidget I have added 3 pages, say, they are:
    1)page_Main
    2)page_User
    3)page_Logs

    page_Main is the default page which contains 2 pushbuttons(pB_User and pB_Logs). So the design is such that if I click pB_User, currentWidget changes to page_User and same for pB_Logs.

    Now on page_User, I have a pushbutton (pB_BackUser), which when clicked should set the currentWidget to the previous page (i.e page_Main). I can do this easily by the following code:
    Qt Code:
    1. void MainWindow::on_pB_BackUser_clicked()
    2. {
    3. ui->stackedWidget->setCurrentWidget(ui->page_Main);
    4. }
    To copy to clipboard, switch view to plain text mode 

    But is there any more general way by which I can achieve this?
    I mean some Qt Methods, which when called automatically take you to the previous page or widget? I tried with the following methods like :-
    focusNextChild() , focusNextPrevChild() ,focusPreviousChild ()
    but without much success.

    I would be really glad if anyone can help me out, please.

    With regards,
    Sattu

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStackedWidget

    no. focus methods are only for widgets which are currently visible. You are doing it in the right way.

  3. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QStackedWidget

    Quote Originally Posted by nish View Post
    no. focus methods are only for widgets which are currently visible. You are doing it in the right way.
    Thanks Nish, but what about this 2 methods:

    Qt Code:
    1. previousInFocusChain (), nextInFocusChain ()
    To copy to clipboard, switch view to plain text mode 

    This 2 methods return Widget*. When I use them like this:
    Qt Code:
    1. ui->stackedWidget->setCurrentWidget(ui->stackedWidget->previousInFocusChain());
    To copy to clipboard, switch view to plain text mode 

    But I get the following Application Output:
    QStackedWidget::setCurrentWidget: widget 0x3eb2d8 not contained in stack


    My main purpose is that I need a more general way of achieving this type of operations, instead of hard-coating the WidgetNames. Please help.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStackedWidget

    Quote Originally Posted by sattu View Post
    Thanks Nish, but what about this 2 methods:

    Qt Code:
    1. previousInFocusChain (), nextInFocusChain ()
    To copy to clipboard, switch view to plain text mode 
    dont you see "focus" in these methods also? they all fall in the same criteria i mentioned you about.

    This 2 methods return Widget*. When I use them like this:
    Qt Code:
    1. ui->stackedWidget->setCurrentWidget(ui->stackedWidget->previousInFocusChain());
    To copy to clipboard, switch view to plain text mode 

    But I get the following Application Output:


    My main purpose is that I need a more general way of achieving this type of operations, instead of hard-coating the WidgetNames. Please help.
    use index instead of widgets. something like-

    Qt Code:
    1. void setPreviousWidget()
    2. {
    3. int index = stackWidget->currentIndex() - 1;
    4.  
    5. if ( index < 0 )
    6. index = stackWidget->count() - 1;//go to last widget (or do not change if you like, return from here).
    7.  
    8. statckWidget->setCurrentIndex(index);
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to nish for this useful post:

    sattu (28th September 2011)

  6. #5
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QStackedWidget

    Thanks a lot Nish,

    This INDEX stuff works a lot great. Thanks once again for the help.

    With Regards,
    Sattu.
    Last edited by sattu; 28th September 2011 at 13:43.

  7. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStackedWidget

    Quote Originally Posted by sattu View Post
    Thanks a lot Chris,
    You got my nick wrong.

  8. #7
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QStackedWidget

    Oops sorry, My mistake. Thanks Giving Statement modified

Similar Threads

  1. QStackedLayout / QStackedWidget
    By morraine in forum Newbie
    Replies: 15
    Last Post: 12th July 2013, 09:16
  2. get my widget from QStackedWidget
    By szisziszilvi in forum Newbie
    Replies: 4
    Last Post: 22nd August 2011, 08:14
  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

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.