Results 1 to 10 of 10

Thread: switching between pages

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy switching between pages

    Hi,

    I have developed few ui pages: Sample1.ui, Sample2.ui, Sample3.ui....

    Now what i want is that on button click of Sample1.ui, my page Sample2.ui gets loaded and Sample1.ui gets closed...

    To close it i got the function MainWindow.close()...

    But am not able to get any function for swtiching between pages...

    Please help me finding the solution to it...

    Thanking you,
    Kapil

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: switching between pages

    The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
    Load and add your page widgets to a stacked widget, and then just switch the currently shown page widget according to the button click..

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: switching between pages

    Hi,

    This means that what i have to do is that create a slot, and then on the signal button click i will execute that slot which will load the required Form using the function addwidget().

    Is this what u meant?

    If not then plz try to open up a bit on the use of QStackedWidget...

    Thanking you,
    Kapil

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: switching between pages

    Quote Originally Posted by Kapil
    This means that what i have to do is that create a slot, and then on the signal button click i will execute that slot which will load the required Form using the function addwidget().
    You should add your page widgets to the stacked widget only once (eg. in some constructor or so). Then, according to button click signals, your custom slot should decide which widget in the stack to set as current.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: switching between pages

    Actually you could add your buttons in a QButtonGroup with id's corresponding page indexes in the stack widget. Then you don't need a custom slot and you can connect button group's buttonClicked(int) signal directly to the stack widget's setCurrentIndex(int) slot.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: switching between pages

    Maybe you could also consider using a tab widget?

    Anyway check this example, it might help:
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: switching between pages

    Maybe you should just use separate forms and show() one and close() the other?

  8. #8
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: switching between pages

    Hi,

    I tried doing the same but am getting lots of errors.. Also i am new to C++ so i am also getting errors 'coz of C++...

    I haev attached the code.. Plz help me in finding out the errors...

    thanking you,
    Kapil
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: switching between pages


  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: switching between pages

    In your code:
    Qt Code:
    1. void ActionClass::actionSlot()
    2. {
    3. secondpg = new QWidget;
    4. Ui_Second::Form _ui;
    5. _ui.setupUi(secondpg);
    6.  
    7. firstpg->close();
    8. secondpg->show();
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    You can't access "firstpg" like this. You need a pointer to it somewhere. I suggest you work a bit more on learning pure C++ before using Qt.

Similar Threads

  1. Paint QTextDocument splitted by pages 1/5 and edit txt
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2017, 12:14
  2. Replies: 6
    Last Post: 9th September 2008, 20:43
  3. Replies: 1
    Last Post: 7th August 2008, 14:49
  4. Replies: 4
    Last Post: 13th August 2007, 15:28
  5. adding widgets to tabWidgets pages
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 23rd November 2006, 09:59

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.