Reputation: 14081
I have created a traditional Qt (widget based) GUI, something like this: MainWindow::MainWindow(parent) : QMainWindow(parent)
This is designed by Qt Creator as forms (mainwindow.ui
), aka Design Mode
. Everything works fine. But the GUI code with all widgets, initializing the corresponding models, and functionality gets quit long. I'd like to refactor to small units. Things I came up with:
MyTableView::QTableView
contains the specialized model, as well the signal/slot handling between model and widget. This reduces the amount of code in MainWindow
. However, I do loose the capability to design the GUI via Qt Creator's Design mode
. cpp
files). It still represents one class, but less code in one file.So, how could I better partition my GUI class?
Upvotes: 0
Views: 722
Reputation: 720
If you still want to uncouple the initialization of widgets by derived widgets, you can use "promote to ..." option in Qt designer. Steps:
Borrowed a picture:
Upvotes: 1
Reputation: 11
In a recent project, we had pretty restrictive uncoupling requirements (especially not to be too strongly linked to Qt). What we used to do based on MVC-like pattern is:
Note that this structure might not be suitable for small projects.
Upvotes: 1