| 1 | /* |
| 2 | KStyle for KF5 |
| 3 | SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <[email protected]> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include "kstyle.h" |
| 9 | |
| 10 | #include <QApplication> |
| 11 | #include <QDialog> |
| 12 | #include <QDialogButtonBox> |
| 13 | #include <QLayout> |
| 14 | #include <QPushButton> |
| 15 | #include <QTextEdit> |
| 16 | #include <QVBoxLayout> |
| 17 | #include <QWidget> |
| 18 | |
| 19 | void showDialog() |
| 20 | { |
| 21 | QDialog dialog; |
| 22 | |
| 23 | auto *layout = new QVBoxLayout(&dialog); |
| 24 | |
| 25 | QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, &dialog); |
| 26 | |
| 27 | // Useful to change the text because setting the text triggers setShortcut |
| 28 | box->button(QDialogButtonBox::Ok)->setText(QStringLiteral("Send")); |
| 29 | QObject::connect(box, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); |
| 30 | QObject::connect(box, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); |
| 31 | |
| 32 | auto usefulWidget = new QTextEdit(&dialog); |
| 33 | layout->addWidget(usefulWidget); |
| 34 | layout->addWidget(box); |
| 35 | |
| 36 | // Make sure we test ctrl+return acceptance with the focus on the button |
| 37 | usefulWidget->setFocus(); |
| 38 | |
| 39 | dialog.resize(200, 200); |
| 40 | dialog.exec(); |
| 41 | } |
| 42 | |
| 43 | int main(int argc, char **argv) |
| 44 | { |
| 45 | QApplication app(argc, argv); |
| 46 | app.setStyle(new KStyle); |
| 47 | |
| 48 | QWidget w; |
| 49 | auto *layout = new QVBoxLayout(&w); |
| 50 | |
| 51 | QPushButton *showDialogButton = new QPushButton(QStringLiteral("Dialog"), &w); |
| 52 | QObject::connect(showDialogButton, &QPushButton::clicked, &showDialog); |
| 53 | layout->addWidget(showDialogButton); |
| 54 | w.resize(200, 200); |
| 55 | w.show(); |
| 56 | |
| 57 | return app.exec(); |
| 58 | } |