Unsolved QStackedWidget: Loading the widget/class object
-
I am working on a QStackedWidget based application. when the application runs then load all the classes with initial settings. How can I reload the class object when that particular widget is being displayed? because it has to adapt to the settings.
-
@ahsan737
It is not clear what you mean in this question.If you need the widget to completely reset when "loading" the page, you might discard the current widget and do a fresh
new ...
. If that is what you are saying. -
@JonB I want the widget to reload all the parameters when it comes in view (set as current widget in QStackedWidget). I am loading designer UI forms to stackwidget. Currently it is being loaded with the very initial parameters, and not adapting to the recent changes.
-
@ahsan737
If you mean the user makes changes in the widget and then when he goes back there the changes are lost, than actually sounds like you are reloading the widget from the UI template each time? You only want to load the template once to create an instance (at start-up time, or the first time the page is to be shown), put that into the stacked widget and then do not reload from the design-time template? -
@JonB let me explain it clearly, I want that when widget No. 6 gets loaded then it should adapt to the changes made in the previous 5 widgets. But currently widget 6 is being loaded with default values, and isn't responding to the changes made (parameters defined) in previous screens.
-
@ahsan737
Still don't understand! How does "a widget adapt to the changes made in the previous 5 widgets", what does that mean? You have to do whatever to pick stuff up from other widgets (pages?) if you want those copied into another widget (page)? Is that what you asking about??Maybe show some code?
-
@JonB the application is in a flow. a user is being asked to input parameters one by one (first 5 or 6 screens), and then a graph is being plotted (at screen 7) which will take the previous data as input.
-
This post is deleted! -
@ahsan737 said in QStackedWidget: Loading the widget/class object:
@JonB the application is in a flow. a user is being asked to input parameters one by one (first 5 or 6 screens), and then a graph is being plotted (at screen 7) which will take the previous data as input.
So you have to write code for that, it won't happen "automatically". I don't know what else to say.
BTW, if you have 6 pages of prompting the user for input data, and a final page which does something with that information, and you would like the user to be able to navigate forwards and perhaps backwards through the pages changing data (your "flow"), you should perhaps be using
QWizard
+QWizardPage
s, https://doc.qt.io/qt-5/qwizard.html + https://doc.qt.io/qt-5/qwizardpage.html. -
Hi @ahsan737,
If I understand well your needs, you have two ways:- QStackedWidget emits the signal curentChanged() whether a given widget that is in the stack is displayed (unless for the first one). So you can intercept the signal to update the content of the widget,
- When a widget, in the stack, is called, its member showEvent() is called. So, you can override this function to update the display.