Results 1 to 5 of 5

Thread: QStackedWidget: can put same widget on different pages?

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QStackedWidget: can put same widget on different pages?

    I have a QStackedWidget with 7 pages, each with different widgets. There is one widget common to all of the pages: QPushButton *setRotation. Unfortunately, when I compile/run my application, the QPushButton doesn't show up on the pages. To fix this, I created *setRotation[7], and add setRotation[0] to page 0, setRotation[1] to page 1, etc...

    Is my assumption correct: that a single widget cannot be on 2 or more pages of a QStackedWidget? The solution above is OK for a simple QPushButton, but I want to add more complex widgets now, that will retain settings from page to page.

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QStackedWidget: can put same widget on different pages?

    Yes, a widget can only have one parent at a time. In a QStackedWidget, one of the pages is its parent.

    Other than your solution, you could change the parent (and location?) of the widget whenever you change the page.

    But perhaps it would be much more practical to leave the button out of the QStackedWidget entirely.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStackedWidget: can put same widget on different pages?

    Quote Originally Posted by Michiel View Post
    Other than your solution, you could change the parent (and location?) of the widget whenever you change the page.
    ok, thanks. will look into this.

    Quote Originally Posted by Michiel View Post
    But perhaps it would be much more practical to leave the button out of the QStackedWidget entirely.
    I should have been more clear: there are 7 pages now to the QStackedWidget, but I'm adding more, some of which won't have the setRotation widget.

  4. #4
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QStackedWidget: can put same widget on different pages?

    Quote Originally Posted by vonCZ View Post
    I should have been more clear: there are 7 pages now to the QStackedWidget, but I'm adding more, some of which won't have the setRotation widget.
    Even so, it might be easier to make the button invisible when you go to those pages. It's hard to say without knowing the whole situation. I'm sure you can figure it out.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  5. #5
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStackedWidget: can put same widget on different pages?

    yeah, I'd thought about show()/hide(), but I had thought the buttons, when hidden, would still occupy space in their Layouts (which wouldn't look good). I just tried it, however, and see now that everything slides evenly to the proper justification, so this should take care of it. Thanks for the tips.

Similar Threads

  1. Custom tab widget question
    By PrimeCP in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 11:17
  2. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  3. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  4. adding widgets to tabWidgets pages
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 23rd November 2006, 09:59
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.