QT Windows:圆形工具提示

发布于 2025-01-24 14:50:43 字数 1148 浏览 0 评论 0原文

我需要QT5 + Windows中的圆形工具提示。 无法通过样式表设置工具提示的圆角,以下样式表不起作用:

QToolTip
{
    font-family: Calibri;
    font-size: 13pt;
    border-radius: 0.5em;
    ...
}

我不能覆盖小部件的oottip事件,因为我们的应用程序在显示了蹒跚的地方太多的地方。 我正在尝试以下面的方式进行操作:

int ThemeStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
{    
    switch (hint)
    {
    case SH_ToolTip_Mask:
    {
    if (option) 
    {
        if (QStyleHintReturnMask* mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) 
        {
            static const int cornerRadius = 5;

            QPainterPath path;
            path.addRoundedRect(option->rect, cornerRadius, cornerRadius);

            mask->region = QRegion(path.toFillPolygon().toPolygon()); // Unable to use QPolygonF ?
        }
    }       
    }
    break;
//....

结果,我变得太角落了:

“在此处输入图像说明”

是否有某种全球方法可以在qt5中制作平滑的圆形玩具?

I need rounded tooltips in Qt5 + Windows.
Rounded corners for tooltips cannot be set via stylesheet, the following stylesheet is not working:

QToolTip
{
    font-family: Calibri;
    font-size: 13pt;
    border-radius: 0.5em;
    ...
}

I cannot override tootip events for widgets, because our application has too many places where tootips are shown.
I'm trying to do it in the following way:

int ThemeStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
{    
    switch (hint)
    {
    case SH_ToolTip_Mask:
    {
    if (option) 
    {
        if (QStyleHintReturnMask* mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) 
        {
            static const int cornerRadius = 5;

            QPainterPath path;
            path.addRoundedRect(option->rect, cornerRadius, cornerRadius);

            mask->region = QRegion(path.toFillPolygon().toPolygon()); // Unable to use QPolygonF ?
        }
    }       
    }
    break;
//....

As a result, I get too angular corners:

enter image description here

Is there some global way to make smooth rounded tootips in Qt5?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭白衣梦中忆 2025-01-31 14:50:43

您在em中提供边框半径,尝试此样式表:

 QToolTip {
     border: 2px solid darkkhaki;
     padding: 5px;
     border-radius: 10px;
     opacity: 200;
 }

You're giving border radius in em, try this style sheet:

 QToolTip {
     border: 2px solid darkkhaki;
     padding: 5px;
     border-radius: 10px;
     opacity: 200;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文