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.
  • Himanshu chardeH Himanshu charde

    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

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Himanshu-charde I don't think this is a good idea. Tooltips are meant to be used for short texts, not something user has to scroll.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • qwasder85Q Offline
      qwasder85Q Offline
      qwasder85
      wrote on last edited by qwasder85
      #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.

      Himanshu chardeH 1 Reply Last reply
      1
      • Himanshu chardeH Himanshu charde

        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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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"?

        Himanshu chardeH 1 Reply Last reply
        2
        • JonBJ JonB

          @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"?

          Himanshu chardeH Offline
          Himanshu chardeH Offline
          Himanshu charde
          wrote on 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);

          Pl45m4P 1 Reply Last reply
          0
          • qwasder85Q qwasder85

            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.

            Himanshu chardeH Offline
            Himanshu chardeH Offline
            Himanshu charde
            wrote on 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);
            }

            qwasder85Q 1 Reply Last reply
            0
            • Himanshu chardeH Himanshu charde

              @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);

              Pl45m4P Online
              Pl45m4P Online
              Pl45m4
              wrote on 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

              Himanshu chardeH 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @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)

                Himanshu chardeH Offline
                Himanshu chardeH Offline
                Himanshu charde
                wrote on 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
                • Himanshu chardeH Himanshu charde

                  @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);
                  }

                  qwasder85Q Offline
                  qwasder85Q Offline
                  qwasder85
                  wrote on 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
                  • Himanshu chardeH Offline
                    Himanshu chardeH Offline
                    Himanshu charde
                    wrote on last edited by
                    #10

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

                    H 1 Reply Last reply
                    0
                    • Himanshu chardeH Himanshu charde

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

                      H Offline
                      H Offline
                      HTTP_SEA
                      wrote on 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
                      0
                      • H HTTP_SEA

                        @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 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