PDA

View Full Version : QStackedWidget: can put same widget on different pages?



vonCZ
13th August 2007, 14:20
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.

Michiel
13th August 2007, 14:30
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.

vonCZ
13th August 2007, 14:37
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.


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.

Michiel
13th August 2007, 14:39
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.

vonCZ
13th August 2007, 16:28
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.