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. [SOLVED] Constantly updating tooltip text without moving the mouse
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Constantly updating tooltip text without moving the mouse

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

    Hi,

    is there a way to update the text of a tooltip which is already visible without any extra event (no mouse movement).

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      I haven't tried it, but couldn't you create a timer when you get the tooltip event and use the timer to update the tooltip?

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

        I update the tooltip in the painEvent but it seems that it rendered only once so the updates are not displayed.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          ScottR
          wrote on last edited by
          #4

          Here's a simple example of how it can work.

          Find the tooltip example.

          To Sortingbox.h, add:

          private:
          QPoint pos;

          To Sortingbox.cpp, add:
          void SortingBox::update()
          {
          static int ncalls = 0;
          QString tt;
          tt = QString("Tooltip #%1").arg(ncalls++);
          QToolTip::showText(pos, tt);
          }
          And change the event method to this:
          bool SortingBox::event(QEvent *event)
          {
          if (event->type() == QEvent::ToolTip) {
          QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
          QTimer *timer = new QTimer(this);
          connect(timer, SIGNAL(timeout()), this, SLOT(update()));
          timer->start(500);
          pos = helpEvent->globalPos();
          int index = itemAt(helpEvent->pos());
          if (index != -1) {
          QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
          } else {
          QToolTip::hideText();
          event->ignore();
          }

              return true;
          }
          return QWidget::event(event);
          

          }

          The tooltip for items will update constantly (every 1/2 second) with "Tooltip #x" with x incrementing from 0.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            ScottR
            wrote on last edited by
            #5

            Sorry about the formatting.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="ScottR" date="1390323723"]Sorry about the formatting.[/quote]

              Just put your code between '@' tags and it will be fine :)

              (Z(:^

              1 Reply Last reply
              0
              • B Offline
                B Offline
                butterface
                wrote on last edited by
                #7

                Thanks for the code but I found another way. This works because I am changing the tooltips text every time my values change so I listen to QEvent::ToolTipChange. This leads to the following code:

                @
                bool MyClass::event(QEvent *ev)
                {
                if (ev->type() == QEvent::ToolTip)
                {
                QHelpEvent *helpEvent = static_cast<QHelpEvent *>(ev);
                m_ToolTipPos = helpEvent->globalPos();
                }
                else if (ev->type() == QEvent::ToolTipChange)
                {
                if (underMouse() && !m_ToolTipPos.isNull())
                QToolTip::showText(m_ToolTipPos, toolTip());
                }
                return QWidget::event(ev);
                }
                @

                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