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. Is it possible to use tooltip with scrollbar in qt?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use tooltip with scrollbar in qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 7 Posters 1.1k Views 2 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.
  • Q Offline
    Q Offline
    qwasder85
    wrote on 11 Dec 2019, 14:32 last edited by qwasder85 12 Nov 2019, 14:33
    #3

    If that's really what you want, then you should overwrite your widget's "event"-function, filter for the ToolTip-event and display a QLineEdit with the text at the mouse pointer position.
    Something like this:

    bool MyWidget::event(QEvent* p_event)
    {
        if (QEvent::ToolTip == p_event->type())
        {
            QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event);
            
            // Create a QLineEdit with your text and position it at p_help_event.globalPos()
    
            return true;
        }
        
        return QWidget::event(p_event);
    }
    

    Of course you need to make sure that the QLineEdit disappears once it loses focus, like when the user clicks anywhere else but the QLineEdit (there are also events for this). Hope that helps.

    H 1 Reply Last reply 12 Dec 2019, 06:44
    1
    • H Himanshu charde
      11 Dec 2019, 13:25

      Actually the contents written inside line edit is too long the tooltip fails to show whole data i want the scrollbar do the work so that the complete text can be read

      J Offline
      J Offline
      JonB
      wrote on 11 Dec 2019, 16:34 last edited by
      #4

      @Himanshu-charde
      Both @jsulm's & @qwasder85's answers are good, in their respective ways.

      Another possibility for you to consider: https://doc.qt.io/qt-5/qwhatsthis.html

      "What's This?" help texts are typically longer and more detailed than tooltips,

      You could have a look to see if you could leverage this for your "long tooltips"?

      H 1 Reply Last reply 12 Dec 2019, 06:32
      2
      • J JonB
        11 Dec 2019, 16:34

        @Himanshu-charde
        Both @jsulm's & @qwasder85's answers are good, in their respective ways.

        Another possibility for you to consider: https://doc.qt.io/qt-5/qwhatsthis.html

        "What's This?" help texts are typically longer and more detailed than tooltips,

        You could have a look to see if you could leverage this for your "long tooltips"?

        H Offline
        H Offline
        Himanshu charde
        wrote on 12 Dec 2019, 06:32 last edited by
        #5

        @JonB
        actually i am trying to set whatsthis to the TableWidget_item but it is not working for me
        QAction *newAct = new QAction(tr("&New"),ui->TW_Contents);
        newAct->setShortcut(tr("Ctrl+N"));
        newAct->setStatusTip(tr("Create a new file"));
        newAct->setWhatsThis(strToolTipText);

        P 1 Reply Last reply 12 Dec 2019, 09:00
        0
        • Q qwasder85
          11 Dec 2019, 14:32

          If that's really what you want, then you should overwrite your widget's "event"-function, filter for the ToolTip-event and display a QLineEdit with the text at the mouse pointer position.
          Something like this:

          bool MyWidget::event(QEvent* p_event)
          {
              if (QEvent::ToolTip == p_event->type())
              {
                  QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event);
                  
                  // Create a QLineEdit with your text and position it at p_help_event.globalPos()
          
                  return true;
              }
              
              return QWidget::event(p_event);
          }
          

          Of course you need to make sure that the QLineEdit disappears once it loses focus, like when the user clicks anywhere else but the QLineEdit (there are also events for this). Hope that helps.

          H Offline
          H Offline
          Himanshu charde
          wrote on 12 Dec 2019, 06:44 last edited by
          #6

          @qwasder85 said in Is it possible to use tooltip with scrollbar in qt?:

          bool MyWidget::event(QEvent* p_event)
          {
          if (QEvent::ToolTip == p_event->type())
          {
          QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event);
          // Create a QLineEdit with your text and position it at p_help_event.globalPos()
          QLineEdit *lineEtool=new QLineEdit(this);
          ui->lineEtool->setText(strToolTipText);
          //here i am stucked how to position it
          return true;
          }
          return QWidget::event(p_event);
          }

          Q 1 Reply Last reply 12 Dec 2019, 09:54
          0
          • H Himanshu charde
            12 Dec 2019, 06:32

            @JonB
            actually i am trying to set whatsthis to the TableWidget_item but it is not working for me
            QAction *newAct = new QAction(tr("&New"),ui->TW_Contents);
            newAct->setShortcut(tr("Ctrl+N"));
            newAct->setStatusTip(tr("Create a new file"));
            newAct->setWhatsThis(strToolTipText);

            P Offline
            P Offline
            Pl45m4
            wrote on 12 Dec 2019, 09:00 last edited by
            #7

            @Himanshu-charde

            Hi,

            have you tried this? In fact you are using a QTableWidget (Model / View), this could solve your problem.

            Note that, if you want to show tooltips in an item view, the model/view architecture provides functionality to set an item's tool tip; e.g., the QTableWidgetItem::setToolTip() function. However, if you want to provide custom tool tips in an item view, you must intercept the help event in the QAbstractItemView::viewportEvent() function and handle it yourself.
            (from https://doc.qt.io/qt-5/qtooltip.html#details)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            H 1 Reply Last reply 12 Dec 2019, 09:31
            0
            • P Pl45m4
              12 Dec 2019, 09:00

              @Himanshu-charde

              Hi,

              have you tried this? In fact you are using a QTableWidget (Model / View), this could solve your problem.

              Note that, if you want to show tooltips in an item view, the model/view architecture provides functionality to set an item's tool tip; e.g., the QTableWidgetItem::setToolTip() function. However, if you want to provide custom tool tips in an item view, you must intercept the help event in the QAbstractItemView::viewportEvent() function and handle it yourself.
              (from https://doc.qt.io/qt-5/qtooltip.html#details)

              H Offline
              H Offline
              Himanshu charde
              wrote on 12 Dec 2019, 09:31 last edited by
              #8

              @Pl45m4 I am not able to show large amount of text on the tooltip i am trying to find different alternative so that the complete text can be read

              1 Reply Last reply
              0
              • H Himanshu charde
                12 Dec 2019, 06:44

                @qwasder85 said in Is it possible to use tooltip with scrollbar in qt?:

                bool MyWidget::event(QEvent* p_event)
                {
                if (QEvent::ToolTip == p_event->type())
                {
                QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event);
                // Create a QLineEdit with your text and position it at p_help_event.globalPos()
                QLineEdit *lineEtool=new QLineEdit(this);
                ui->lineEtool->setText(strToolTipText);
                //here i am stucked how to position it
                return true;
                }
                return QWidget::event(p_event);
                }

                Q Offline
                Q Offline
                qwasder85
                wrote on 12 Dec 2019, 09:54 last edited by
                #9

                @Himanshu-charde Have you tried

                lineEtool->move(p_help_event->globalPos();
                

                You may even want to consider showing the QLineEdit in a QDialog, for more control.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Himanshu charde
                  wrote on 13 Dec 2019, 13:22 last edited by
                  #10

                  thank you
                  @jsulm @qwasder85 @JonB @Pl45m4 for your responses

                  H 1 Reply Last reply 11 Apr 2020, 11:45
                  0
                  • H Himanshu charde
                    13 Dec 2019, 13:22

                    thank you
                    @jsulm @qwasder85 @JonB @Pl45m4 for your responses

                    H Offline
                    H Offline
                    HTTP_SEA
                    wrote on 11 Apr 2020, 11:45 last edited by
                    #11

                    @Himanshu-charde Hi!
                    I meet the same problem recently, could you please tell me if you solve it and how?
                    Thank you very much!

                    mrjjM 1 Reply Last reply 11 Apr 2020, 13:57
                    0
                    • H HTTP_SEA
                      11 Apr 2020, 11:45

                      @Himanshu-charde Hi!
                      I meet the same problem recently, could you please tell me if you solve it and how?
                      Thank you very much!

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 11 Apr 2020, 13:57 last edited by
                      #12

                      @HTTP_SEA

                      Hi
                      I think he intercepted the tooltip event and showed
                      a QLineEdit instead. (see code higher up )

                      However, it's not clear how he made it disappear again like
                      the tooltip does.

                      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