How to show ToolTip for QLineEdit with out mousehovering ..!
-
@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? -
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..?
-
@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? -
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
-
@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 fromledt
in fact your ledt is doing nothing, but leaking memory x)
-
@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.- 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
- 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)
-
@raven-worx
you're right, it seemes, that I missed thecmConfLineEdit->setParent(ledt);
part. Only noticed it, when you wrote it down! -
@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.
-
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(); }
-
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