QtDesigner/c++: Is there a way to only instantiate the same component once if it appears across multiple pages?
-
I have a multi-page application that has some consistent components/widgets across all pages and a different area for different things depending on what page the user is on. All of the pages are made using QtDesigner .ui files and c++. My problem is that I have to instantiate each permanent component on every single c++ class (copy-pasting code) that I use. These components are for getting the current time/date and showing battery life kind of things.
Is there a way to just instantiate the components once and then have the data carry over across .ui files ?
Layout example:
Any help/advice is greatly appreciated!
-
Hi,
Either:
Make these permanent components independent widgets and reuse them as needed.Or just make one of your core widget and make each page an independent widget that you will instanciate and put in that central widget which I guess should be a QStackedWidget.
-
@SGaist said in QtDesigner/c++: Is there a way to only instantiate the same component once if it appears across multiple pages?:
Or just make one of your core widget and make each page an independent widget that you will instanciate and put in that central widget which I guess should be a QStackedWidget.
To clarify @SGaist's 2nd point:
- Put your permanent components directly in the central widget of the Main Window. Do not put them in your individual pages.
- Implement your "Different Display" as a
QStackedWidget
and add your individual pages to the stacked widget.