Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Infinite tooltip
Qt 6.11 is out! See what's new in the release blog

Infinite tooltip

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 910 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It's working fine for me in a small testcase as long as the focus does not change.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by Bonnie
        #3

        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;
        }
        
        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved