是否可以在 OS X 上重新设置 QProgressBar 的样式?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您可以使用QSS,请参阅QProgressBar 示例
Sure, you can use QSS, see QProgressBar example