diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-12-31 10:03:41 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-01-02 07:50:45 +0100 |
| commit | 3419c299369ac1da94ba5710aaf5f5f65c38c33c (patch) | |
| tree | 768f67760f53df52044a71aa1d1ace03c93ce0a5 /examples/sql/sqlbrowser/qsqlconnectiondialog.h | |
| parent | 53826d1cde26f825d1983476c6697f72130e351f (diff) | |
sqlbrowser example: use idiomatic Qt [2/3]: use button-box / override accept()
- The old code used two QPushButtons in a QHBoxLayout to provide
Ok/Cancel buttons. This hard-codes the positions and text (and
icons) of these buttons, instead of adapting to the platform style.
The new code simply uses QDialogButtonBox, which is designed for
this purpose.
- Also, the old code connected the Ok button's clicked() signal to a
custom slot that then called QDialog::accept(). This means that the
code in the custom slot is not executed when the dialog is accepted
by other means (e.g. return press in one of the line edits
("auto-default"), though I'm not sure here).
The new code uses the idiomatic Qt way of overriding
QDialog::accept() instead, and connects the button-box's accepted()
signal to it. This is done in the .ui file, so it already works in
Designer preview.
- Finally, the old code made a manual connection from the Cancel
button to QDialog::reject().
The new code uses the Qt idiom of connecting in the .ui file
directly, using QDialogButtonBox::rejected() as the signal.
Amends 2690822428deec4f0c08f4d118d69a7c6036369e, which, however,
inherited all of the above from even older code.
Pick-to: 6.9 6.8
Change-Id: I83afd6156a0811e0c0f99f2480625ea6b69ff78b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/sql/sqlbrowser/qsqlconnectiondialog.h')
| -rw-r--r-- | examples/sql/sqlbrowser/qsqlconnectiondialog.h | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/examples/sql/sqlbrowser/qsqlconnectiondialog.h b/examples/sql/sqlbrowser/qsqlconnectiondialog.h index 605fe376c2c..b5654ea9133 100644 --- a/examples/sql/sqlbrowser/qsqlconnectiondialog.h +++ b/examples/sql/sqlbrowser/qsqlconnectiondialog.h @@ -28,8 +28,7 @@ public: int port() const; bool useInMemoryDatabase() const; -private slots: - void onOkButton(); + void accept() override; private: Ui::QSqlConnectionDialogUi *m_ui; |
