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. QToolTip not showing when QLineEdit is focused
Qt 6.11 is out! See what's new in the release blog

QToolTip not showing when QLineEdit is focused

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 4.4k 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.
  • K Offline
    K Offline
    Kamba
    wrote on last edited by
    #1

    Hey,

    I have Subclassed QLineEdit and added focusInEvent and focusOutEvent like this

    void QLineEditSubclass::focusInEvent(QFocusEvent *e)
    {
        QLineEdit::focusInEvent(e);
        emit(focused(true));
    }
    
    void QLineEditSubclass::focusOutEvent(QFocusEvent *e)
    {
        QLineEdit::focusOutEvent(e);
        emit(focused(false));
    }
    

    Focus slot is working, but QToolTip is not showing.

    void Class::on_lineEdit_focused(bool focused)
    {
        QPoint pos = mapToGlobal(ui->lineEdit->pos());
        qDebug() << pos;
        QToolTip::showText(pos, "Test text");
        qDebug() << QToolTip::text();
        qDebug() << QToolTip::isVisible();
    }
    

    QDebug is printing pos and text of the QToolTip. isVisible returns false and QToolBox itself is not showing.

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

      Hi,

      Why not call setToolTip on your widget ?

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

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not call setToolTip on your widget ?

        K Offline
        K Offline
        Kamba
        wrote on last edited by
        #3

        @SGaist
        It shows tooltip only if mouse cursor is on the widget. I forgot to mention that tooltip should be shown even without cursor.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          try adding the widget to the tooltip call QToolTip::showText(pos, "Test text",this);

          From the docs:

          The rect is in the coordinates of the widget you specify with w. If the rect is not empty you must specify a widget. Otherwise this argument can be 0 but it is used to determine the appropriate screen on multi-head systems.

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          K 1 Reply Last reply
          0
          • VRoninV VRonin

            try adding the widget to the tooltip call QToolTip::showText(pos, "Test text",this);

            From the docs:

            The rect is in the coordinates of the widget you specify with w. If the rect is not empty you must specify a widget. Otherwise this argument can be 0 but it is used to determine the appropriate screen on multi-head systems.

            K Offline
            K Offline
            Kamba
            wrote on last edited by Kamba
            #5

            @VRonin
            Tried

            QToolTip::showText(pos, "Test text", this);
            

            and

            QToolTip::showText(pos, "Test text", ui->lineEdit);
            

            without any success.

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

              The QToolTip might not be the best tool then. Why do you need a permanent QToolTip ?

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

              K 1 Reply Last reply
              0
              • SGaistS SGaist

                The QToolTip might not be the best tool then. Why do you need a permanent QToolTip ?

                K Offline
                K Offline
                Kamba
                wrote on last edited by
                #7

                @SGaist
                I need to have tooltip when qlineedit is focused to inform user about acceptable datatype, value range and small description.
                I think I could make a special widget for this, which acts like tooltip. It could change location, text and visibility based on focused widget.

                D 1 Reply Last reply
                0
                • K Kamba

                  @SGaist
                  I need to have tooltip when qlineedit is focused to inform user about acceptable datatype, value range and small description.
                  I think I could make a special widget for this, which acts like tooltip. It could change location, text and visibility based on focused widget.

                  D Offline
                  D Offline
                  Devopia53
                  wrote on last edited by Devopia53
                  #8

                  @Kamba

                  Hi.

                  something like this:

                  QLineEditSubclass::QLineEditSubclass(QWidget *parent)
                  : QLineEdit(parent)
                  {
                      setToolTip("Test text");
                  }
                  
                  void QLineEditSubclass::focusInEvent(QFocusEvent *e)
                  {
                      QLineEdit::focusInEvent(e);
                      
                      auto    gPos = (parentWidget()) ? parentWidget()->mapToGlobal(pos()) : pos();
                      auto    toolTipEvent = new QHelpEvent(QEvent::ToolTip, pos(), gPos);
                      QApplication::postEvent(this, toolTipEvent);
                  }
                  

                  Not tested... :)

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

                    @Kamba: Looks like a QWidget with a QLineEdit on top of a QLabel and you set your text on the QLabel. You can style it if you have special color needs.

                    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