Stylesheet example: Get rid of auto-connection slots

Change-Id: I55d89cf33e5f9c8aef3a3dfbbdcd212415d35bcb
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Alexander Volkov 2018-11-02 16:56:56 +03:00 committed by Alexander Volkov
parent 065c4021ad
commit a51b7844ca
3 changed files with 21 additions and 16 deletions

View File

@ -58,23 +58,23 @@
\c stylesheeteditor.ui. \c stylesheeteditor.ui.
\quotefromfile widgets/stylesheet/stylesheeteditor.cpp \quotefromfile widgets/stylesheet/stylesheeteditor.cpp
\skipto on_styleCombo_activated \skipto setStyleName
\printline on_styleCombo_activated \printline setStyleName
Sets the specified \a styleName and grays the \c applyButton. Sets the specified \a styleName and grays the \c applyButton.
\skipto on_styleSheetCombo_activated \skipto setStyleSheetName
\printline on_styleSheetCombo_activated \printline setStyleSheetName
Loads the stylesheet from \c styleSheetName. Loads the stylesheet from \c styleSheetName.
\skipto on_styleTextEdit_textChanged() \skipto setModified()
\printline on_styleTextEdit_textChanged() \printline setModified()
Enables the \c applyButton when the text in the buffer has changed. Enables the \c applyButton when the text in the buffer has changed.
\skipto on_applyButton_clicked() \skipto apply()
\printline on_applyButton_clicked() \printline apply()
Sets the stylesheet properties in \l qApp and disables the \c applyButton. Sets the stylesheet properties in \l qApp and disables the \c applyButton.

View File

@ -59,6 +59,11 @@ StyleSheetEditor::StyleSheetEditor(QWidget *parent)
{ {
ui.setupUi(this); 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$"); QRegularExpression regExp("^.(.*)\\+?Style$");
QString defaultStyle = QApplication::style()->metaObject()->className(); QString defaultStyle = QApplication::style()->metaObject()->className();
QRegularExpressionMatch match = regExp.match(defaultStyle); QRegularExpressionMatch match = regExp.match(defaultStyle);
@ -72,23 +77,23 @@ StyleSheetEditor::StyleSheetEditor(QWidget *parent)
loadStyleSheet("Coffee"); loadStyleSheet("Coffee");
} }
void StyleSheetEditor::on_styleCombo_activated(const QString &styleName) void StyleSheetEditor::setStyleName(const QString &styleName)
{ {
qApp->setStyle(styleName); qApp->setStyle(styleName);
ui.applyButton->setEnabled(false); ui.applyButton->setEnabled(false);
} }
void StyleSheetEditor::on_styleSheetCombo_activated(const QString &sheetName) void StyleSheetEditor::setStyleSheetName(const QString &sheetName)
{ {
loadStyleSheet(sheetName); loadStyleSheet(sheetName);
} }
void StyleSheetEditor::on_styleTextEdit_textChanged() void StyleSheetEditor::setModified()
{ {
ui.applyButton->setEnabled(true); ui.applyButton->setEnabled(true);
} }
void StyleSheetEditor::on_applyButton_clicked() void StyleSheetEditor::apply()
{ {
qApp->setStyleSheet(ui.styleTextEdit->toPlainText()); qApp->setStyleSheet(ui.styleTextEdit->toPlainText());
ui.applyButton->setEnabled(false); ui.applyButton->setEnabled(false);

View File

@ -63,10 +63,10 @@ public:
StyleSheetEditor(QWidget *parent = nullptr); StyleSheetEditor(QWidget *parent = nullptr);
private slots: private slots:
void on_styleCombo_activated(const QString &styleName); void setStyleName(const QString &styleName);
void on_styleSheetCombo_activated(const QString &styleSheetName); void setStyleSheetName(const QString &styleSheetName);
void on_styleTextEdit_textChanged(); void setModified();
void on_applyButton_clicked(); void apply();
private: private:
void loadStyleSheet(const QString &sheetName); void loadStyleSheet(const QString &sheetName);