From a51b7844ca988dcc4d18d18dd0785acf15319413 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Fri, 2 Nov 2018 16:56:56 +0300 Subject: Stylesheet example: Get rid of auto-connection slots Change-Id: I55d89cf33e5f9c8aef3a3dfbbdcd212415d35bcb Reviewed-by: Friedemann Kleint --- examples/widgets/doc/src/stylesheet.qdoc | 16 ++++++++-------- examples/widgets/widgets/stylesheet/stylesheeteditor.cpp | 13 +++++++++---- examples/widgets/widgets/stylesheet/stylesheeteditor.h | 8 ++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/widgets/doc/src/stylesheet.qdoc b/examples/widgets/doc/src/stylesheet.qdoc index 26c5663022..b51f1bed41 100644 --- a/examples/widgets/doc/src/stylesheet.qdoc +++ b/examples/widgets/doc/src/stylesheet.qdoc @@ -58,23 +58,23 @@ \c stylesheeteditor.ui. \quotefromfile widgets/stylesheet/stylesheeteditor.cpp - \skipto on_styleCombo_activated - \printline on_styleCombo_activated + \skipto setStyleName + \printline setStyleName Sets the specified \a styleName and grays the \c applyButton. - \skipto on_styleSheetCombo_activated - \printline on_styleSheetCombo_activated + \skipto setStyleSheetName + \printline setStyleSheetName Loads the stylesheet from \c styleSheetName. - \skipto on_styleTextEdit_textChanged() - \printline on_styleTextEdit_textChanged() + \skipto setModified() + \printline setModified() Enables the \c applyButton when the text in the buffer has changed. - \skipto on_applyButton_clicked() - \printline on_applyButton_clicked() + \skipto apply() + \printline apply() Sets the stylesheet properties in \l qApp and disables the \c applyButton. diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp index 2cc0e969e2..f885964a31 100644 --- a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp +++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp @@ -59,6 +59,11 @@ StyleSheetEditor::StyleSheetEditor(QWidget *parent) { ui.setupUi(this); + connect(ui.styleCombo, &QComboBox::textActivated, this, &StyleSheetEditor::setStyleName); + connect(ui.styleSheetCombo, &QComboBox::textActivated, this, &StyleSheetEditor::setStyleSheetName); + connect(ui.styleTextEdit, &QTextEdit::textChanged, this, &StyleSheetEditor::setModified); + connect(ui.applyButton, &QAbstractButton::clicked, this, &StyleSheetEditor::apply); + QRegularExpression regExp("^.(.*)\\+?Style$"); QString defaultStyle = QApplication::style()->metaObject()->className(); QRegularExpressionMatch match = regExp.match(defaultStyle); @@ -72,23 +77,23 @@ StyleSheetEditor::StyleSheetEditor(QWidget *parent) loadStyleSheet("Coffee"); } -void StyleSheetEditor::on_styleCombo_activated(const QString &styleName) +void StyleSheetEditor::setStyleName(const QString &styleName) { qApp->setStyle(styleName); ui.applyButton->setEnabled(false); } -void StyleSheetEditor::on_styleSheetCombo_activated(const QString &sheetName) +void StyleSheetEditor::setStyleSheetName(const QString &sheetName) { loadStyleSheet(sheetName); } -void StyleSheetEditor::on_styleTextEdit_textChanged() +void StyleSheetEditor::setModified() { ui.applyButton->setEnabled(true); } -void StyleSheetEditor::on_applyButton_clicked() +void StyleSheetEditor::apply() { qApp->setStyleSheet(ui.styleTextEdit->toPlainText()); ui.applyButton->setEnabled(false); diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.h b/examples/widgets/widgets/stylesheet/stylesheeteditor.h index f51af7877c..4105d61d5d 100644 --- a/examples/widgets/widgets/stylesheet/stylesheeteditor.h +++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.h @@ -63,10 +63,10 @@ public: StyleSheetEditor(QWidget *parent = nullptr); private slots: - void on_styleCombo_activated(const QString &styleName); - void on_styleSheetCombo_activated(const QString &styleSheetName); - void on_styleTextEdit_textChanged(); - void on_applyButton_clicked(); + void setStyleName(const QString &styleName); + void setStyleSheetName(const QString &styleSheetName); + void setModified(); + void apply(); private: void loadStyleSheet(const QString &sheetName); -- cgit v1.2.3