summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2021-06-11 13:34:12 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2021-06-14 12:57:21 +0200
commit9f3d2ee5f1621cb23b3297c8b4ef84d8d244b0db (patch)
tree1c7d545475589f8849a5f07c0f022fddff337125
parent482125b15648944d18ae120644f9ffe11b327ff2 (diff)
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 Change-Id: Ife57b5a64154be83f6eab4ef533840c51aefd1f5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io> (cherry picked from commit 178313751273284b1f0167391af721f006a677c5)
-rw-r--r--src/assistant/help/qhelpsearchresultwidget.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp
index 9c01032ba..9d67935f3 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>"
@@ -118,8 +128,10 @@ private slots:
#else
void doSetSource(const QUrl & /*name*/, QTextDocument::ResourceType /*type*/) override {}
#endif
-};
+private:
+ QColor m_linkColor;
+};
class QHelpSearchResultWidgetPrivate : public QObject
{