On a dialog I have a QLineEdit and a button. I want to enable a tool tip for the QLineEdit(in it or under it) when I press the button. Please give me a code snippet.
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- How to get a Component's own ElementRef for re
- Selecting only the first few characters in a strin
Here is a simple example:
As you can see, there is no easy way to just enable the tool tip of some widget. You have to provide global coordinates to
QToolTip::showText
.Another way to do this is to create a
QHelpEvent
yourself and post this event usingQCoreApplication::postEvent
. This way, you can specify the text to be shown in your widget usingQWidget::setToolTip
. You still have to provide global coordinates, though.I am really interested in why you want to do this since tool tips are intended to be shown only when you hover your mouse or when you ask for the "What's this" information. It looks like bad design to use it for something else. If you want to give a message to the user, why don't you use
QMessageBox
?If you need tooltip for QLineEdit, so what is the problem? Just set:
But if you need just to show some text after some
button
was pressed, here the another solution: create a slot, for exampleon_myBytton_clicked()
and connect it to your button. In slot do the setText() function with your text onQLabel
,QTextEdit
and etc widgets located on your form.Hope it help.