Bear
Bear

Reputation: 5152

QT QStackedLayout problem

I would like to ask about QStackedLayout. Now, I have a several widgets added to the QStackedLayout And I want to do sth like that: When user switch to Page X, refresh Page X.

How can I do that? I have a custom code that I want to run when it refreshes Thank You very much

Upvotes: 0

Views: 1053

Answers (3)

Caleb Huitt - cjhuitt
Caleb Huitt - cjhuitt

Reputation: 14941

In my opinion, the best way to handle this situation is through inheritance. Create a class that derives from QWidget that has a virtual update function. Use that as a base class for every page of your stacked widget. In your class that contains the stacked widget, connect a slot to the currentChanged(int index) signal of the stacked widget. In that slot, get the current widget, qobject_cast it to your base type, and (if successful) call the update function on it.

Each class that is a page in your stacked widget should then override the update function and use it to update its information as necessary.

Upvotes: 1

Arnold Spence
Arnold Spence

Reputation: 22272

Based on your comment to mine, it seems like you are looking for a signal that is generated when the current page changes so that you can update the underlying data for the screen. In that case, you would want to hook a slot up to void QStackedWidget::currentChanged(int index)

Upvotes: 1

useraged
useraged

Reputation: 1716

All "pages" are QWidget based classes. If your widgets does not paint itself properly you need to check your widget's code. Generally, while switching pages, visible widget repaint itself. If your widgets does not handle some events you can see glitches.

Anyway, if you want to force a repaint for your "page" you need to call QWidget::update() or (bruteforce method) QWidget::repaint().

Upvotes: 2

Related Questions