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
examples/widgets

View File

@ -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.

View File

@ -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);

View File

@ -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);