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());
精彩评论