Infinite tooltip
-
Hi there,
I need to create an infinite tooltip at mouse position.
From the documentation:
*[static] void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)This is an overloaded function.
This is similar to QToolTip::showText(pos, text, w, rect) but with an extra parameter msecDisplayTime that specifies how long the tool tip will be displayed, in milliseconds.
This function was introduced in Qt 5.2.*I tried this - and it does not have any effect. The tooltip vanishes short after appearing. Tested on windows and macOS.
QString eyedropperToolTip; eyedropperTooltip += "Put some information ..."; QRect rect; QToolTip::showText(ui->graphicsView->mapToGlobal(pos), eyedropperToolTip, nullptr, rect, 10000);Any hint is welcome. thx in advance
-
It's working fine for me in a small testcase as long as the focus does not change.
-
Maybe it is not related to the time, looking into the qtooltip.cpp souce code I find that there're some app events will cause it to hide :
bool QTipLabel::eventFilter(QObject *o, QEvent *e) { switch (e->type()) { #ifdef Q_OS_MACOS case QEvent::KeyPress: case QEvent::KeyRelease: { const int key = static_cast<QKeyEvent *>(e)->key(); // Anything except key modifiers or caps-lock, etc. if (key < Qt::Key_Shift || key > Qt::Key_ScrollLock) hideTipImmediately(); break; } #endif case QEvent::Leave: hideTip(); break; #if defined (Q_OS_QNX) // On QNX the window activate and focus events are delayed and will appear // after the window is shown. case QEvent::WindowActivate: case QEvent::FocusIn: return false; case QEvent::WindowDeactivate: if (o != this) return false; hideTipImmediately(); break; case QEvent::FocusOut: if (reinterpret_cast<QWindow*>(o) != windowHandle()) return false; hideTipImmediately(); break; #else case QEvent::WindowActivate: case QEvent::WindowDeactivate: case QEvent::FocusIn: case QEvent::FocusOut: #endif case QEvent::Close: // For QTBUG-55523 (QQC) specifically: Hide tooltip when windows are closed case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::Wheel: hideTipImmediately(); break; case QEvent::MouseMove: if (o == widget && !rect.isNull() && !rect.contains(static_cast<QMouseEvent*>(e)->pos())) hideTip(); default: break; } return false; }