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 `<qt/>` if it is not yet rich text.
This commit is contained in:
Wladimir J. van der Laan
2012-04-13 17:10:50 +02:00
parent 4c9183e8bb
commit 3793fa09ff
5 changed files with 57 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#define GUIUTIL_H
#include <QString>
#include <QObject>
QT_BEGIN_NAMESPACE
class QFont;
@@ -69,6 +70,23 @@ namespace GUIUtil
// Determine whether a widget is hidden behind other windows
bool isObscured(QWidget *w);
/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
representation if needed. This assures that Qt can word-wrap long tooltip messages.
Tooltips longer than the provided size threshold (in characters) are wrapped.
*/
class ToolTipToRichTextFilter: public QObject
{
Q_OBJECT
public:
ToolTipToRichTextFilter(int size_threshold, QObject *parent);
protected:
bool eventFilter(QObject *obj, QEvent *evt);
private:
int size_threshold;
};
} // namespace GUIUtil
#endif // GUIUTIL_H