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. How to show ToolTip for QLineEdit with out mousehovering ..!
Qt 6.11 is out! See what's new in the release blog

How to show ToolTip for QLineEdit with out mousehovering ..!

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.9k 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.
  • M mounipanditi

    I am trying to show the tooltip for a LineEdit without the mousehovering and by reading some examples and answers in Internet i have tried an example to make it work. But the example is compiling and executing fine but i am unable to achieve my target.

    I know i did some thing wrong, i request your help to do so. Please correct bugs in my code.

    MyLineEdit.h

    #ifndef LINEEDITTOOLTIP_H
    #define LINEEDITTOOLTIP_H
    
    #include <QWidget>
    #include <QLineEdit>
    
    class MyLineEdit : public QLineEdit
    {
      Q_OBJECT
    
    public:
      MyLineEdit(QWidget *parent = 0);
      ~MyLineEdit();
    
    signals:
      void focussed(bool hasFocus);
    
    protected:
      virtual void focusInEvent(QFocusEvent *e);
      virtual void focusOutEvent(QFocusEvent *e);
    };
    
    #endif // LINEEDITTOOLTIP_H
    

    MyLineEdit.cpp

    #include "MyLineEdit.h"
    
    
    MyLineEdit::MyLineEdit(QWidget *parent)
     : QLineEdit(parent)
    {}
    
    MyLineEdit::~MyLineEdit()
    {}
    
    void MyLineEdit::focusInEvent(QFocusEvent *e)
    {
      QLineEdit::focusInEvent(e);
      emit(focussed(true));
    }
    
    void MyLineEdit::focusOutEvent(QFocusEvent *e)
    {
      QLineEdit::focusOutEvent(e);
      emit(focussed(false));
    }
    

    Widget.h

    #include <QWidget>
    #include <QLineEdit>
    #include <QPushButton>
    #include <QDebug>
    #include <QToolTip>
    #include "MyLineEdit.h"
    
    class Widget : public QWidget
    {
        Q_OBJECT
        
    public:
        /*!
         * This is Constructor
         */
        explicit Widget(QWidget *parent = 0);
        MyLineEdit *ledt;
    
        ~Widget();
    private:
        QPushButton *button;
        QLineEdit *cmConfLineEdit;
    
    private slots:
    void showLineEditToolTip(bool);
    void buttonSlot();
    };
    #endif
    

    Widget.cpp

    Widget::Widget(QWidget *parent) :
        QWidget(parent),
    {
        ledt = new MyLineEdit;
       
        button = new QPushButton(this);
        button->setText("Press");
        button->setGeometry(100,50,40,40);
    
        cmConfLineEdit = new QLineEdit;
        cmConfLineEdit->setParent(ledt);
        cmConfLineEdit->setGeometry(100,120,60,30);
    
        connect(button,SIGNAL(clicked()),this,SLOT(buttonSlot()));
        connect(ledt,SIGNAL(focussed(bool)),this,SLOT(showLineEditToolTip(bool)));
    
    void Widget::buttonSlot()
    {
        cmConfLineEdit->setFocusPolicy(Qt::StrongFocus);
    } 
    void Widget::showLineEditToolTip(bool value)
    {
        qDebug()<<"Bool Value is"<<value;
        if(value ==  true)
        {
            QToolTip::showText(QPoint(110,130),"Enter Conf Number",this);
        }
    }
    

    Thanks in Advance,
    Mounika.P

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    @mounipanditi said in How to show ToolTip for QLineEdit with out mousehovering ..!:
    are you sure it is not working?
    QToolTip::showText() expects the position to be in global coordinates on the screen. Maybe you are just overseeing the tooltip?

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    M 1 Reply Last reply
    0
    • raven-worxR raven-worx

      @mounipanditi said in How to show ToolTip for QLineEdit with out mousehovering ..!:
      are you sure it is not working?
      QToolTip::showText() expects the position to be in global coordinates on the screen. Maybe you are just overseeing the tooltip?

      M Offline
      M Offline
      mounipanditi
      wrote on last edited by
      #3

      @raven-worx

      Thanks for the reply,

      I am sure after clicking on the PushButton i am unable to see the qDebug which i have written in the showLineEditToolTip SLOT.

      What i have written is it correct..?

      raven-worxR J.HilkJ 2 Replies Last reply
      0
      • M mounipanditi

        @raven-worx

        Thanks for the reply,

        I am sure after clicking on the PushButton i am unable to see the qDebug which i have written in the showLineEditToolTip SLOT.

        What i have written is it correct..?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #4

        @mounipanditi said in How to show ToolTip for QLineEdit with out mousehovering ..!:

        What i have written is it correct..?

        seems so yes.
        Any other output on the console regarding an unsuccessful connection to the slot?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        M 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @mounipanditi said in How to show ToolTip for QLineEdit with out mousehovering ..!:

          What i have written is it correct..?

          seems so yes.
          Any other output on the console regarding an unsuccessful connection to the slot?

          M Offline
          M Offline
          mounipanditi
          wrote on last edited by
          #5

          @raven-worx

          Nope except the following statement on console i am unable to see anything

          Qt: Session management error: None of the authentication protocols specified are supported

          raven-worxR 1 Reply Last reply
          0
          • M mounipanditi

            @raven-worx

            Thanks for the reply,

            I am sure after clicking on the PushButton i am unable to see the qDebug which i have written in the showLineEditToolTip SLOT.

            What i have written is it correct..?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #6

            @mounipanditi
            I don't think what you've written is correct.

            Let me see, you have a subclass of QLineEdit that has a custom focussed signal,
            that seems ok.

            You create such a custom object:

            ledt = new MyLineEdit;
            //and connect to it
            connect(ledt,SIGNAL(focussed(bool)),this,SLOT(showLineEditToolTip(bool)));
            

            also ok,
            but your buttonSlot connects to this one:

            void Widget::buttonSlot()
            {
                cmConfLineEdit->setFocusPolicy(Qt::StrongFocus);
            } 
            

            which is a normal QLineEdit so you of course won't get Signal from ledt

            in fact your ledt is doing nothing, but leaking memory x)


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • M mounipanditi

              @raven-worx

              Nope except the following statement on console i am unable to see anything

              Qt: Session management error: None of the authentication protocols specified are supported

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #7

              @mounipanditi
              what @J.Hilk wrote is only partially correct, but it lead me to the actual issue.
              The code so far is syntactically correct. Though there is also non-sense contained.

              1. it doesn't make sense to set a focus policy in a slot connected to a button. What should actually happen in this slot? If you want to set the focus to the line edit you should use setFocus() instead
              2. I have no idea why you place a QLineEdit into your custom MyLineEdit widget. Thus the MyLineEdit widget never receives the focus, because the child (plain QLineEdit gets it first)

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              J.HilkJ M 2 Replies Last reply
              0
              • raven-worxR raven-worx

                @mounipanditi
                what @J.Hilk wrote is only partially correct, but it lead me to the actual issue.
                The code so far is syntactically correct. Though there is also non-sense contained.

                1. it doesn't make sense to set a focus policy in a slot connected to a button. What should actually happen in this slot? If you want to set the focus to the line edit you should use setFocus() instead
                2. I have no idea why you place a QLineEdit into your custom MyLineEdit widget. Thus the MyLineEdit widget never receives the focus, because the child (plain QLineEdit gets it first)
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @raven-worx
                you're right, it seemes, that I missed the cmConfLineEdit->setParent(ledt); part. Only noticed it, when you wrote it down!


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @mounipanditi
                  what @J.Hilk wrote is only partially correct, but it lead me to the actual issue.
                  The code so far is syntactically correct. Though there is also non-sense contained.

                  1. it doesn't make sense to set a focus policy in a slot connected to a button. What should actually happen in this slot? If you want to set the focus to the line edit you should use setFocus() instead
                  2. I have no idea why you place a QLineEdit into your custom MyLineEdit widget. Thus the MyLineEdit widget never receives the focus, because the child (plain QLineEdit gets it first)
                  M Offline
                  M Offline
                  mounipanditi
                  wrote on last edited by
                  #9

                  @raven-worx said in How to show ToolTip for QLineEdit with out mousehovering ..!:

                  policy in a slot connected to a butto

                  I understand your point, can you please guide me how to achieve my target to show the ToolTip for a lineEdit with out mouse hovering either by a code snippet or a documented guide.

                  J.HilkJ 1 Reply Last reply
                  0
                  • M mounipanditi

                    @raven-worx said in How to show ToolTip for QLineEdit with out mousehovering ..!:

                    policy in a slot connected to a butto

                    I understand your point, can you please guide me how to achieve my target to show the ToolTip for a lineEdit with out mouse hovering either by a code snippet or a documented guide.

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #10

                    @mounipanditi

                    your example modified:

                    Widget::Widget(QWidget *parent) :
                        QWidget(parent),
                    {
                        ledt = new MyLineEdit;
                        ledt->setGeometry(100,120,60,30);
                       
                        button = new QPushButton(this);
                        button->setText("Press");
                        button->setGeometry(100,50,40,40);
                    
                        connect(button,SIGNAL(clicked()),this,SLOT(buttonSlot()));
                        connect(ledt,SIGNAL(focussed(bool)),this,SLOT(showLineEditToolTip(bool)));
                    
                    void Widget::buttonSlot()
                    {
                        ledt->setFocus();
                    } 
                    

                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    M 1 Reply Last reply
                    1
                    • J.HilkJ J.Hilk

                      @mounipanditi

                      your example modified:

                      Widget::Widget(QWidget *parent) :
                          QWidget(parent),
                      {
                          ledt = new MyLineEdit;
                          ledt->setGeometry(100,120,60,30);
                         
                          button = new QPushButton(this);
                          button->setText("Press");
                          button->setGeometry(100,50,40,40);
                      
                          connect(button,SIGNAL(clicked()),this,SLOT(buttonSlot()));
                          connect(ledt,SIGNAL(focussed(bool)),this,SLOT(showLineEditToolTip(bool)));
                      
                      void Widget::buttonSlot()
                      {
                          ledt->setFocus();
                      } 
                      
                      M Offline
                      M Offline
                      mounipanditi
                      wrote on last edited by mounipanditi
                      #11

                      @J.Hilk

                      Thanks for the reply i was unable to see the Tooltip after modifying the code as you have posted.

                      Please go through the below screen shots

                      https://unsee.cc/dunepima/

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved