How to programatically create dynamic pages
I am developing a wizard-like application which will have two program flows which are similar. I have created each page as a class which inherits from a widget and they have been added to a QStackedWidget to switch between pages.
Between the two program flows there are some pages which are very similar to each other but have slight changes, for examples different text etc. Rather than creating two classes (pages) that are nearly identical I would rather use one and dynamically change it depending on which option the user has selected.
My question is to ask which would be the best approach for this. I have an idea and I would appreciate your feedback.
I was thinking that I could initialise all the variables in the constructor, and then create two functions OptionA and OptionB. Then if the user selects OptionA it could call OptionA and within that function it would display the appropriate widgets.
Is this the correct approach or am I completely wrong?
That sounds reasonable to me. The Page would simply be dynamic and setting some text and show/hide some widgets
depending on previously selection.
Would you recommend creating a class that is responsible for handling the flow of the application? potentially a boolean set to true/false for OptionA/OptionB to control which pages to show and which content to show on each page?
Well i often use a controller class when using a QStackedWidget to allow
flexible navigation. Also it allows for different flows if the Controller uses a index list/map to navigate between
pages and in that way, its easy to have different sequences using the same pages and at the same time
not coupling the navigation logic to the MainWindow/QStackedWidget parent.
So yes, if you application have more than one flow, a data driven approach should turn out very
effective and the flow list could also be used with additional data such as OptionA/B from your case.
Aren't you describing something like a QWizard ?
@mrjj That sounds exactly like what I would like to do, is it possible for you to supply me with some more information on how I could approach this? possibly some pseudo-code or bullet points?
What variables would you recommend storing in the controller class and how would you recommend it communicates with the rest of the classes?