Do you put everything UI related in mainwindow.cpp?
-
For example in an app where you have multiple pages, say a page for showing the data, a page for showing the settings, a page for chatting, etc.;
Do you just have a mainwindow.cpp with :
void createDataView();
void createSettingsView();
createChatView();or do you create different classes for each and make them inherit QWidget or QGraphicsScene and then have a display(QWidget* page) function thats connected to certain actions that switch the page, and set the page as central view.
-
For example in an app where you have multiple pages, say a page for showing the data, a page for showing the settings, a page for chatting, etc.;
Do you just have a mainwindow.cpp with :
void createDataView();
void createSettingsView();
createChatView();or do you create different classes for each and make them inherit QWidget or QGraphicsScene and then have a display(QWidget* page) function thats connected to certain actions that switch the page, and set the page as central view.
@Mbkerdellou
You certainly create separate classes/files for each "item" or "page" which is a widget, of whatever kind. You can use Designer to design them as.uifiles with corresponding class files if you wish. You may create them from the main window but they are their own widgets.As for showing them one at a time, there are many ways. You can show and hide widgets. If you want to have a
QMainWindowwith a single central widget which changes, you can use QStackedWidget: you put each of your widgets as a "page" and it only displays one at a time, under your control. -
logically that is entirely up to you, but no, I don't. I try to follow an OO approach that closely models what I'm trying to accomplish.
-
thank you @JonB and @Kent-Dorfman
-
Hi,
In addition to my fellows, never use a god like class that does everything. You're in for maintenance hell.
Split your UI in logical pieces. That will allow to also test them independently.
-
@JonB said in Do you put everything UI related in mainwindow.cpp?:
you can use QStackedWidget:
@SGaist said in Do you put everything UI related in mainwindow.cpp?:
Split your UI in logical pieces
Theese are true options, If you want to open different window, you use create new class. Stacked or Tab widgets are good.