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. Show tooltip under mouse cursor
Qt 6.11 is out! See what's new in the release blog

Show tooltip under mouse cursor

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k 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.
  • L Offline
    L Offline
    lipposkiman
    wrote on last edited by
    #1

    Hello all!!

    I would like to show a tooltip exactly under the mouse cursor ( and i've done it), but it disappear immediately and it seems that is calling the leaveEvent of the widget that has created the tooltip.
    It happen even if i don't move the mouse cursor.

    Any suggestion please?

    Many thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DBoosalis
      wrote on last edited by
      #2

      How about creating your own ToolTip and use its methods showText & hideText based on anything you want - mouse movement, timer.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        How are you doing your tooltip ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lipposkiman
          wrote on last edited by
          #4

          Many thanks for your answers,
          here the code used at the moment.

          @class myview : public QTreeView {

          bool viewportEvent(QEvent * event) {

          if (event->type() == QEvent::ToolTip) {

          QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
          QModelIndex index = indexAt(helpEvent->pos());

          QRect r(visualRect(index));
          QString tipText(index.data(0).toString());

          if (r.width() >= fontMetrics().width(tipText)) {
          event->ignore();
          QToolTip::hideText();
          return true;
          }
          else {

          QPoint p = r.topLeft();
          

          p -= QPoint(2,
          #ifdef Q_WS_WIN
          21
          #else
          16
          #endif
          );
          event->accept();
          QToolTip::showText(mapToGlobal(p), tipText);
          return true;
          }
          }
          return QTreeView::viewportEvent(event);
          }

          ...

          ...

          }@

          Create my own tool tip class is not easy for me and take long time.
          Maybe there is another way.

          Thanks

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What about handling the Qt::ToolTipRole in your model ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

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