PDA

View Full Version : QToolTip Qusetion



chandan
17th February 2011, 10:21
Hi Everyone,
Can I show a ToolTip without hovering over the widget? I have seen QToolTip showText method, which requires a point but how can I get that point?

For your kind information, I am creating a login dialog where user will enter username and password. If the login details is not valid then I want to show a tool tip on the password field saying that "Your login details is not valid" but without hovering over the password field. The message should come automatically.

Is it achievable?

Thanks.
Chandan

stampede
17th February 2011, 18:00
Since QToolTip::showText() expects position in global screen coordinates, you can calculate position of tooltip using the QWidget::mapToGlobal():

QToolTip::showText(lineEdit->mapToGlobal(QPoint()) + QPoint( lineEdit->width(),0 ),"string to show");
widget->mapToGlobal(QPoint()) returns coordinates of the top-left corner of the widget (in screen coordinates), so you can for example translate it to match right corner of the widget ( as above ).