是否可以在 OS X 上重新设置 QProgressBar 的样式?

发布于 2024-12-21 18:00:40 字数 932 浏览 2 评论 0原文

使用 QStyle 子类并设置调色板的方法不起作用(但对 MyStyle 的其他基本样式有效)。

void MyStyle::drawControl(ControlElement control, const QStyleOption *option,
                          QPainter *painter, const QWidget *widget) const
{    
    switch(control) 
    {
        case CE_ProgressBar: 
        {
            const QStyleOptionProgressBarV2 * pOpts =
            static_cast<const QStyleOptionProgressBarV2 *>(option);
            QStyleOptionProgressBarV2 oOpts(*pOpts);

            QColor progressColor(QColor::fromHsl(50, 160, 162));
            oOpts.palette.setColor(QPalette::Highlight, progressColor);

            // BASESTYLE is QMacStyle
            BASESTYLE::drawControl(control, &outputOptions, painter, widget);
        }
            break;

        default:
            BASESTYLE::drawControl(control, option, painter, widget);
    }
}

有其他方法可以控制 OS X 下小部件的外观吗? (或者说这是完全不可能的?)

The approach using a QStyle Subclass, and setting the palette doesn't work (but does work for other base styles to MyStyle).

void MyStyle::drawControl(ControlElement control, const QStyleOption *option,
                          QPainter *painter, const QWidget *widget) const
{    
    switch(control) 
    {
        case CE_ProgressBar: 
        {
            const QStyleOptionProgressBarV2 * pOpts =
            static_cast<const QStyleOptionProgressBarV2 *>(option);
            QStyleOptionProgressBarV2 oOpts(*pOpts);

            QColor progressColor(QColor::fromHsl(50, 160, 162));
            oOpts.palette.setColor(QPalette::Highlight, progressColor);

            // BASESTYLE is QMacStyle
            BASESTYLE::drawControl(control, &outputOptions, painter, widget);
        }
            break;

        default:
            BASESTYLE::drawControl(control, option, painter, widget);
    }
}

Is there some other way to control the appearance of widgets under OS X? (Or is it completely impossible?)

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

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

发布评论

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

评论(1

初见终念 2024-12-28 18:00:40

当然,您可以使用QSS,请参阅QProgressBar 示例

Sure, you can use QSS, see QProgressBar example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文