Christian
Christian

Reputation: 1552

QT Background-Image

I tried to add a gradient background on my main QWidget by adding (background-image:url(images/background.png) to its stylesheet but I noticed HUGE performance drops and I haven't written any code yet.

background image is a gradient , 16bit 1x800 px png.

So my question is, how can I add a nice gradient to my QWidgets / QFrames without slowing down the program? Using only the designer.

Upvotes: 1

Views: 935

Answers (1)

Ferenc Deak
Ferenc Deak

Reputation: 35448

Try this:

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);

and modify freely the colors and the positions. Although that this is code, it might be useful.

Upvotes: 2

Related Questions