Results 1 to 5 of 5

Thread: stack widget pages using pushbutton

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default stack widget pages using pushbutton

    Hi

    How to navigate stackwidget pages using PushButtons?
    Which method needs to be called whenever pushbutton is clicked, so that it opens a particluar stackwidget page.

    Thanks & Regards,
    Arun.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stack widget pages using pushbutton

    You must use the setCurrentIndex(), currentIndex() and count() methods of QStackedWidget.

  3. #3
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: stack widget pages using pushbutton

    Can you help in navigating 3 buttons with the help a small piece of code.

    Thanks & Regards,
    Arun

  4. #4
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: stack widget pages using pushbutton

    Thanks, it solved now.
    For those who implement stack widget pages using pushbutton, here is snippet of code.
    in a simple way. As I am using 3-4 buttons it is easy to use this way.
    May be for more number of buttons you can choose any other method for best use.

    Code:
    Qt Code:
    1. static int currentIndex = 0; // Global
    2. .......
    3. ......
    4. ....
    5. class::class() ///constructor
    6. {
    7. QObject::connect(pushbutton1, clicked(), this, page1());
    8. QObject::connect(pushbutton2, clicked(), this, page2());
    9. }
    10. void class::page1()
    11. {
    12. currentIndex = stackedWidget->currentIndex();
    13. if( currentIndex < stackedWidget->count())
    14. {
    15. stackedWidget->setCurrentIndex(0); // page1
    16. }
    17. }
    18. void class::page2()
    19. {
    20. currentIndex = stackedWidget->currentIndex();
    21. if( currentIndex < stackedWidget->count())
    22. {
    23. stackedWidget->setCurrentIndex(1); // for page2
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    Note: For other buttons and pages replace stackedWidget->setCurrentIndex(number with appropriate page).

    Thanks & Regards,
    Arun.
    Last edited by jacek; 21st March 2008 at 11:07. Reason: missing [code] tags

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: stack widget pages using pushbutton

    Please don't use global variables --- you can do the same using member variables and your class will be reusable.

    Also you can save a lot of typing by using QSignalMapper.

Similar Threads

  1. Replies: 8
    Last Post: 1st October 2015, 07:23
  2. Replies: 4
    Last Post: 13th August 2007, 15:28
  3. Replies: 1
    Last Post: 7th August 2007, 08:27
  4. Previewing a stack widget dialog
    By mikeh in forum Qt Tools
    Replies: 4
    Last Post: 2nd October 2006, 10:19
  5. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 12:07

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.