开发者

How to set the background QBrush of a QMdiArea widget to a gradient of system colors?

I'm trying to set the background QBrush of a QMdiArea widget in Qt4 to a gradient of system colors.

Here's some code I have now:

QPrios::QPrios(i开发者_如何学Cnt &argc, char **argv): QApplication(argc, argv)
{
        // ... 
        QPalette pal = this->palette();
        QLinearGradient grad;
        grad.setColorAt(0, pal.text().color());
        grad.setColorAt(1, pal.window().color());
        _mdi->setBackground(QBrush(grad));
        // ...
}

What happens is that the background becomes just a solid color, the one set with grad.setColorAt(1, pal.window().color());

What am I doing wrong?


Set the gradient's coordinate mode. You might also want to set the gradient's start and stop points at constructor if you want a vertical gradient.

QLinearGradient grad(QPointF(0, 0), QPointF(0, 1));
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
grad.setColorAt(0, pal.text().color());
grad.setColorAt(1, pal.window().color());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜