diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-03-18 17:02:33 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-06-14 13:08:23 +0200 |
commit | 6db694453636a0f7b8c4f51048f352da80d912d2 (patch) | |
tree | 27e9f8704418848acff193d901bd5a9af4961ce4 | |
parent | 99a6a44a0f0dda3b6459fcc45fd6e43279c95a32 (diff) | |
download | qttools-6db694453636a0f7b8c4f51048f352da80d912d2.tar.gz |
Assistant: Make QResultWidget linkColor stylable
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
Change-Id: Ife57b5a64154be83f6eab4ef533840c51aefd1f5
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r-- | src/assistant/help/qhelpsearchresultwidget.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp index 052eadb53..53878cc20 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,6 +69,15 @@ public: connect(this, &QTextBrowser::anchorClicked, this, &QResultWidget::requestShowLink); setContextMenuPolicy(Qt::NoContextMenu); + setLinkColor(palette().color(QPalette::Link)); + } + + 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 QVector<QHelpSearchResult> results, bool isIndexing) @@ -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 setSource(const QUrl & /* name */) override {} + +private: + QColor m_linkColor; }; |