1

我尝试通过在其样式表中添加 (background-image:url(images/background.png) 来在我的主 QWidget 上添加渐变背景,但我注意到性能大幅下降并且我还没有编写任何代码。

背景图像是渐变,16 位 1x800 像素 png。

所以我的问题是,如何在不减慢程序速度的情况下为我的 QWidgets / QFrames 添加一个漂亮的渐变?仅使用设计器。

4

1 回答 1

2

尝试这个:

QPalette thePalette = this->palette();
QLinearGradient gradient(0, 0, 0, 50);
gradient.setColorAt(0, QColor(227,177,27));
gradient.setColorAt(0.25, QColor(170,177,167));

gradient.setColorAt(1, Qt::white);
QBrush brush(gradient);
thePalette.setBrush(QPalette::Window, brush);
setPalette(thePalette);

并自由修改颜色和位置。虽然这是代码,但它可能很有用。

于 2012-06-22T10:29:51.487 回答