【问题标题】:Is it possible to re-style a QProgressBar on OS X?是否可以在 OS X 上重新设置 QProgressBar 的样式?
【发布时间】:2012-01-22 05:28:35
【问题描述】:

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

【问题讨论】:

  • 如果注释掉 CE_ProgressBar 案例中的所有代码,你会得到什么? QProgressBar 是否只绘制任何内容/垃圾?如果是这样,那将表明您走在正确的轨道上,但是 BASESTYLE::drawControl)( 忽略了您的序言。
  • 是的,我可以确认,如果 CE_ProgressBar 案例中的 BASESTYLE::drawControl() 被删除,则不会绘制进度条。 (BASESTYLE 当然是QMacStyle)。
  • 在最坏的情况下,您始终可以将 BASESTYLE::drawControl() 中的代码复制并粘贴到您自己的方法中,然后对其进行修改以适应...但可能会有更优雅方法比那个。您必须查看 BASESTYLE::drawControl() 的源代码并了解 CE_ProgressBar 案例是如何实现的,这应该可以让您了解您可以对其行为产生什么影响。
  • 犯下在 Mac 上使用跨平台 UI 框架的罪行剥夺了您关注风格的权利 ;)

标签: c++ macos qt qstyle


【解决方案1】:

当然,你可以使用QSS,见QProgressBar example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2014-05-12
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多