Hello,
If someone could help me with getting a gradient in the background of a button, I'd appreciate it.
I would expect the following code to make the button's background be a gradient from red to white vertically from the top of the button to the bottom.
linearGrad.setColorAt(0, Qt::red);
linearGrad.setColorAt(1, Qt::white);
b->setPalette(palette);
QPushButton *b = new QPushButton("Hi", this);
QLinearGradient linearGrad(0, 0, 0, b->height());
linearGrad.setColorAt(0, Qt::red);
linearGrad.setColorAt(1, Qt::white);
QPalette palette = b->palette();
palette.setBrush(QPalette::Button, QBrush(linearGrad));
b->setPalette(palette);
To copy to clipboard, switch view to plain text mode
All it does, though, is make the button black. Since it makes the button black, I know that I am successfully changing the palette and reapplying it, but I'm just not changing it in the right way.
Any help would be great.
Thanks,
Derek
Bookmarks