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.
This commit is contained in:
Arnaud Bienner 2013-04-01 17:54:33 +02:00
parent 2081c30893
commit bc5aa4055c
2 changed files with 21 additions and 1 deletions

View File

@ -304,6 +304,24 @@ void FancyTabBar::paintEvent(QPaintEvent *event)
paintTab(&p, currentIndex()); 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<QHelpEvent*>(event);
QToolTip::showText(he->globalPos(), text);
} else {
QToolTip::hideText();
}
return true;
}
return QWidget::event(event);
}
void FancyTab::enterEvent(QEvent*) void FancyTab::enterEvent(QEvent*)
{ {
fadeIn(); fadeIn();
@ -364,6 +382,7 @@ void FancyTabBar::addTab(const QIcon& icon, const QString& label) {
FancyTab *tab = new FancyTab(this); FancyTab *tab = new FancyTab(this);
tab->icon = icon; tab->icon = icon;
tab->text = label; tab->text = label;
tab->setToolTip(label);
m_tabs.append(tab); m_tabs.append(tab);
qobject_cast<QVBoxLayout*>(layout())->insertWidget(layout()->count()-1, tab); qobject_cast<QVBoxLayout*>(layout())->insertWidget(layout()->count()-1, tab);
} }

View File

@ -64,7 +64,7 @@ protected:
bool eventFilter(QObject* o, QEvent* e); bool eventFilter(QObject* o, QEvent* e);
}; };
class FancyTab : public QWidget{ class FancyTab : public QWidget {
Q_OBJECT Q_OBJECT
Q_PROPERTY(float fader READ fader WRITE setFader) Q_PROPERTY(float fader READ fader WRITE setFader)
@ -82,6 +82,7 @@ public:
QString text; QString text;
protected: protected:
bool event(QEvent *);
void enterEvent(QEvent *); void enterEvent(QEvent *);
void leaveEvent(QEvent *); void leaveEvent(QEvent *);