From bc5aa4055cc21d2efcd4668d20cccfe68a383735 Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Mon, 1 Apr 2013 17:54:33 +0200 Subject: [PATCH] Show a tooltip for sidebar tabs: only when needed for large side bar, always in the other cases, as I guess text will be elided most of the time. Update issue 1202 This work around this issue a bit. --- src/widgets/fancytabwidget.cpp | 19 +++++++++++++++++++ src/widgets/fancytabwidget.h | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/widgets/fancytabwidget.cpp b/src/widgets/fancytabwidget.cpp index d39fa2fe6..56038e9be 100644 --- a/src/widgets/fancytabwidget.cpp +++ b/src/widgets/fancytabwidget.cpp @@ -304,6 +304,24 @@ void FancyTabBar::paintEvent(QPaintEvent *event) paintTab(&p, currentIndex()); } +bool FancyTab::event(QEvent* event) +{ + if (event->type() == QEvent::ToolTip) { + QFontMetrics metrics (font()); + int text_width = metrics.width(text); + + if (text_width > sizeHint().width()) { + // The text is elided: show the tooltip + QHelpEvent* he = static_cast(event); + QToolTip::showText(he->globalPos(), text); + } else { + QToolTip::hideText(); + } + return true; + } + return QWidget::event(event); +} + void FancyTab::enterEvent(QEvent*) { fadeIn(); @@ -364,6 +382,7 @@ void FancyTabBar::addTab(const QIcon& icon, const QString& label) { FancyTab *tab = new FancyTab(this); tab->icon = icon; tab->text = label; + tab->setToolTip(label); m_tabs.append(tab); qobject_cast(layout())->insertWidget(layout()->count()-1, tab); } diff --git a/src/widgets/fancytabwidget.h b/src/widgets/fancytabwidget.h index f2d12bce2..cbdbb2167 100644 --- a/src/widgets/fancytabwidget.h +++ b/src/widgets/fancytabwidget.h @@ -64,7 +64,7 @@ protected: bool eventFilter(QObject* o, QEvent* e); }; -class FancyTab : public QWidget{ +class FancyTab : public QWidget { Q_OBJECT Q_PROPERTY(float fader READ fader WRITE setFader) @@ -82,6 +82,7 @@ public: QString text; protected: + bool event(QEvent *); void enterEvent(QEvent *); void leaveEvent(QEvent *);