diff options
| author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-06-11 13:34:12 +0200 |
|---|---|---|
| committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-06-14 11:55:31 +0200 |
| commit | 178313751273284b1f0167391af721f006a677c5 (patch) | |
| tree | de892cf4a2df15de4277907cb794a566d4c432a9 | |
| parent | 0aa36661440005d7c4618164e5d51d19dac529ca (diff) | |
| download | qttools-178313751273284b1f0167391af721f006a677c5.tar.gz | |
Assistant: Make QResultWidget linkColor styleable
Add a property "linkColor" of QColor type to the
QResultWidget class. Now it's possible to style
the link color in search result widget through the
following stylesheet:
QResultWidget
{
qproperty-linkColor: red;
}
Fixes: QTBUG-74353
Pick-to: 5.15 6.1 6.2
Change-Id: Ife57b5a64154be83f6eab4ef533840c51aefd1f5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
| -rw-r--r-- | src/assistant/help/qhelpsearchresultwidget.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp index 513599575..12d689dc6 100644 --- a/src/assistant/help/qhelpsearchresultwidget.cpp +++ b/src/assistant/help/qhelpsearchresultwidget.cpp @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QResultWidget : public QTextBrowser { Q_OBJECT + Q_PROPERTY(QColor linkColor READ linkColor WRITE setLinkColor) public: QResultWidget(QWidget *parent = nullptr) @@ -68,9 +69,18 @@ public: connect(this, &QTextBrowser::anchorClicked, this, &QResultWidget::requestShowLink); setContextMenuPolicy(Qt::NoContextMenu); + setLinkColor(palette().color(QPalette::Link)); } - void showResultPage(const QList<QHelpSearchResult> results, bool isIndexing) + QColor linkColor() const { return m_linkColor; } + void setLinkColor(const QColor &color) + { + m_linkColor = color; + const QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(m_linkColor.name()); + document()->setDefaultStyleSheet(sheet); + } + + void showResultPage(const QList<QHelpSearchResult> &results, bool isIndexing) { QString htmlFile; QTextStream str(&htmlFile); @@ -88,10 +98,10 @@ public: } for (const QHelpSearchResult &result : results) { - str << "<div style=\"text-align:left; font-weight:bold\"><a href=\"" - << result.url().toString() << "\">" << result.title() << "</a>" - "<div style=\"color:green; font-weight:normal;" - " margin:5px\">" << result.snippet() << "</div></div><p></p>"; + str << "<div style=\"text-align:left\"><a href=\"" + << result.url().toString() << "\">" + << result.title() << "</a></div>" + "<div style =\"margin:5px\">" << result.snippet() << "</div>"; } } else { str << "<div align=\"center\"><br><br><h2>" @@ -114,6 +124,9 @@ signals: private slots: void doSetSource(const QUrl & /*name*/, QTextDocument::ResourceType /*type*/) override {} + +private: + QColor m_linkColor; }; |
