有可能在OS X上重新设计QProgressBar吗?

Is it possible to re-style a QProgressBar on OS X?

本文关键字:QProgressBar OS 有可能      更新时间:2023-10-16

使用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下是否有其他方法来控制小部件的外观?(还是完全不可能?)

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