From 3793fa09ff920fc720dfad3738f105d2c9563662 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 13 Apr 2012 17:10:50 +0200 Subject: Allow Qt to wrap long tooltips (fixes #1063) Implemented without having to touch any translation: by listening for QEvent::ToolTipChange events, then rewriting the tooltips to prefix `` if it is not yet rich text. --- src/qt/guiutil.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/qt/guiutil.cpp') diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index f1e8a5f1b..3b8f8c76f 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -214,5 +214,29 @@ bool isObscured(QWidget *w) && checkPoint(QPoint(w->width()/2, w->height()/2), w)); } +ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject *parent): + size_threshold(size_threshold), QObject(parent) +{ + +} + +bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt) +{ + if(evt->type() == QEvent::ToolTipChange) + { + QWidget *widget = static_cast(obj); + QString tooltip = widget->toolTip(); + if(!Qt::mightBeRichText(tooltip) && tooltip.size() > size_threshold) + { + // Prefix to make sure Qt detects this as rich text + // Escape the current message as HTML and replace \n by
+ tooltip = "" + HtmlEscape(tooltip, true); + widget->setToolTip(tooltip); + return true; + } + } + return QObject::eventFilter(obj, evt); +} + } // namespace GUIUtil -- cgit v1.2.3