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 immediatly

Show Tooltip immediatly

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 13.7k Views
  • 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.
  • Fuel 0F Offline
    Fuel 0F Offline
    Fuel 0
    wrote on last edited by
    #1

    I have some QToolBars with QActions in it. Each one has a Tooltip, but i dont like it, that it takes time the Tooltip shows. Is there a Possibility to show the Tooltip directly, if i enter the Widget?

    DiracsbracketD 1 Reply Last reply
    0
    • Fuel 0F Fuel 0

      I have some QToolBars with QActions in it. Each one has a Tooltip, but i dont like it, that it takes time the Tooltip shows. Is there a Possibility to show the Tooltip directly, if i enter the Widget?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @Fuel-0
      Try this:
      https://stackoverflow.com/questions/13720465/how-to-remove-the-time-delay-before-a-qtooltip-is-displayed

      1 Reply Last reply
      0
      • Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on last edited by
        #3

        The Qt Tool Tips Example could help

        1 Reply Last reply
        0
        • Fuel 0F Offline
          Fuel 0F Offline
          Fuel 0
          wrote on last edited by
          #4

          Slowly i think its not possible. Thanks for your Help, but all the Examples are similar to the setToolTip Method. You can set ToolTips on different Elements/Widgets.

          Its strange. When the Application is started and the Buttons are not hovered something happens in the Background, because if i hover, then it takes some Seconds the Tooltip shows. If i hover from one to another Button then the Tooltip shows directly. But if i leave the Buttons and wait again some Seconds and try to hover again, then i have the Effect again, that it takes some Seconds the Tooltip shows.

          DiracsbracketD 1 Reply Last reply
          0
          • Fuel 0F Fuel 0

            Slowly i think its not possible. Thanks for your Help, but all the Examples are similar to the setToolTip Method. You can set ToolTips on different Elements/Widgets.

            Its strange. When the Application is started and the Buttons are not hovered something happens in the Background, because if i hover, then it takes some Seconds the Tooltip shows. If i hover from one to another Button then the Tooltip shows directly. But if i leave the Buttons and wait again some Seconds and try to hover again, then i have the Effect again, that it takes some Seconds the Tooltip shows.

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by Diracsbracket
            #5

            @Fuel-0 said in Show Tooltip immediatly:

            Slowly i think its not possible

            Actually, there is an uggly workaround which seems to achieve what you want, but has a number of other issues, which may be impractical to resolve:

            In the example below, I created a menu with three QActions, which were also added to the main toolbar (all done in Qt Designer).

            1. Clear the tooltip on each action widget in the toolbar.
              (As per this link:
              https://stackoverflow.com/questions/27243214/remove-tooltip-of-qaction-when-add-it-to-qtoolbar-in-qt)
            2. Install an eventFilter on each button widget of the toolbar.
            3. Connect the hovered signal for each action to a custom showTip() slot
            4. in showTip() , show a QToolTip with the desired text, depending on the action triggered and at the location corresponding to the toolbar button.
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                ui->menuTest->setToolTipsVisible(false);
            
                foreach (QToolButton* button, ui->mainToolBar->findChildren<QToolButton*>())
                    button->installEventFilter(this);
            
                connect(ui->actiontest1, SIGNAL(hovered()), this, SLOT(showTip()));
                connect(ui->actiontest2, SIGNAL(hovered()), this, SLOT(showTip()));
                connect(ui->actiontest3, SIGNAL(hovered()), this, SLOT(showTip()));
            }
            
            bool MainWindow::eventFilter(QObject* o, QEvent* e)
            {
                if (e->type() == QEvent::ToolTip)
                  return true;
            
                return QMainWindow::eventFilter(o, e);
            }
            
            void MainWindow::showTip()
            {
                QAction* act = qobject_cast<QAction *>(sender());
                QWidget* widget;
                widget = ui->mainToolBar->widgetForAction(act);
            
                //To exclude showing tooltip when menu is hovered (tooltip would be at wrong pos)
                if (widget->rect().contains(widget->mapFromGlobal(QCursor::pos())))
                {
                    QPoint point = widget->mapToGlobal(QPoint(10,10));
            
                    if (act == ui->actiontest1)
                        QToolTip::showText(point, "test1");
                    else if (act == ui->actiontest2)
                        QToolTip::showText(point, "test2");
                    else if (act == ui->actiontest3)
                        QToolTip::showText(point, "test3");
                }
            }
            

            This works in achieving instant tooltip display as soon as the toolbar button is hovered upon, but has several issues:

            1. The tooltip is visible as long as you are hovering over the button
            2. The tooltip is shown even if the Menu is in the drop-down state and hiding the toolbar partially but the cursor happens to be over a (covered) toolbar button.
            3. The tooltips on the corresponding menu must be disabled, otherwise they will be shown at the wrong location (since showTip() will show them at the toolbar button's location).

            In other words, too much hassle to compensate for a small tooltip delay which seems to occur when any other control/application had focus before hovering over the toolbar button.

            1 Reply Last reply
            1
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #6

              The amount of delay before a tooltip is shown is controlled by the style. You can override it by creating a proxy style like this:

              class MyProxyStyle : public QProxyStyle
              {
              public:
                  using QProxyStyle::QProxyStyle;
              
                  int styleHint(StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
                  {
                      if (hint == QStyle::SH_ToolTip_WakeUpDelay)
                      {
                          return 0;
                      }
              
                      return QProxyStyle::styleHint(hint, option, widget, returnData);
                  }
              };
              

              This will set the delay to 0 for all widgets. If you want to set the delay only for the toolbar actions you can add an extra condition:

              if (hint == QStyle::SH_ToolTip_WakeUpDelay && widget && widget->inherits(QToolButton::staticMetaObject.className()))
              

              You set this style for your app like this:

              qApp->setStyle(new MyProxyStyle(qApp->style()));
              
              DiracsbracketD 1 Reply Last reply
              6
              • Chris KawaC Chris Kawa

                The amount of delay before a tooltip is shown is controlled by the style. You can override it by creating a proxy style like this:

                class MyProxyStyle : public QProxyStyle
                {
                public:
                    using QProxyStyle::QProxyStyle;
                
                    int styleHint(StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
                    {
                        if (hint == QStyle::SH_ToolTip_WakeUpDelay)
                        {
                            return 0;
                        }
                
                        return QProxyStyle::styleHint(hint, option, widget, returnData);
                    }
                };
                

                This will set the delay to 0 for all widgets. If you want to set the delay only for the toolbar actions you can add an extra condition:

                if (hint == QStyle::SH_ToolTip_WakeUpDelay && widget && widget->inherits(QToolButton::staticMetaObject.className()))
                

                You set this style for your app like this:

                qApp->setStyle(new MyProxyStyle(qApp->style()));
                
                DiracsbracketD Offline
                DiracsbracketD Offline
                Diracsbracket
                wrote on last edited by
                #7

                @Chris-Kawa said in Show Tooltip immediatly:

                You can override it by creating a proxy style like this

                Awesome! Thanks!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sammonius
                  wrote on last edited by sammonius
                  #8

                  (pretend this is deleted)
                  Wouldn't this work?
                  https://doc.qt.io/qt-6/qwidget.html#toolTipDuration-prop

                  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