在 Qt 中聚焦时显示 QLineEdit 的工具提示
我发现我可以在 QLineEdit 上设置工具提示,如下所示:
equation = new QLineEdit();
equation->setToolTip("Example: a*b+c+~c");
但是,我希望在 QLineEdit 聚焦时显示工具提示。 我该怎么做?
提前致谢。
I found that I can set a tooltip on a QLineEdit as such:
equation = new QLineEdit();
equation->setToolTip("Example: a*b+c+~c");
However, I would like the tooltip to be displayed when that QLineEdit is focused.
How do I do that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够通过子类化 QLineEdit 并重写 focusInEvent(...) 来完成此任务:
I was able to accomplish this by subclassing QLineEdit and overriding focusInEvent(...) as such:
我建议您查看以下示例:工具提示示例
当您的 LineEdit 获得焦点时,您可以显示工具提示,也许可以通过连接到此信号:
这里还有一些关于焦点的非常简洁的信息:QFocusEvent 类参考
希望它能有所帮助!
I would suggest that you have a look at the following example : Tool Tips Example
You could show the tooltip when your LineEdit is getting the focus, maybe by connecting to this signal:
There is also some pretty neat informations about Focus here : QFocusEvent Class Reference
Hope it helps a bit !