如何使用 CSS 和 QT 圆 QToolTip 角 [英] How to round QToolTip corners with CSS and QT

查看:92
本文介绍了如何使用 CSS 和 QT 圆 QToolTip 角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请发布一些工作示例.下面的一个有两个边框:黑色的矩形背景框和带有圆形边缘的白色轮廓.我不敢相信以前没有做过.

Please post some working example. The one below makes two borders: the rectangular background frame in black and a white outline with rounded edge. I can't believe it has not been done before.

app.setStyleSheet("QToolTip {
font-size:9pt;
color:white; padding:2px;
border-width:2px;
border-style:solid;
border-radius:20px;
background-color: black;
border: 1px solid white;}")

推荐答案

解决方案是设置自定义 mask 在工具提示小部件上.我可以想到两种方法:

The solution is to set a custom mask on tooltip widget. I can think of two ways of doing that:

  • Implement an own QStyle with a mask returned for QStyle::SH_ToolTip_Mask style hint. That is a generic way as default QToolTip would use this mask (example).

使用适当的掩码创建基于自定义 QToolTip 的类,然后使用 QHelpEvent(QEvent::ToolTip)小部件的事件以显示它.这不是通用解决方案,因为它需要过滤所有需要自定义工具提示的小部件上的事件.

Create a custom QToolTip based class with a proper mask and then use QHelpEvent (QEvent::ToolTip) event of your widget to show it. It's not a generic solution as it requires to filter events on all widgets which need custom tooltip.

这篇关于如何使用 CSS 和 QT 圆 QToolTip 角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆