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:
parent
2081c30893
commit
bc5aa4055c
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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 *);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user