[Interest] QPalette or QLinearGradient does not work on sub widget

Berkay Elbir berkayelbir at gmail.com
Thu Mar 31 14:18:49 CEST 2016


Hello all,

I want to ask a question about QPalette and QLinearGradient.

I want to brush my sub widget with QLinerGradient. I have created ui by
using QtDesigner.

[image: enter image description here] <http://i.stack.imgur.com/5JzSK.png>

But I can not brush this widget by using this code.(ui.colorBarWidget is
normal QWidget was created by QtDesigner.)

   QPalette palette;
   QLinearGradient
gradient(ui.colorBarWidget->rect().topLeft(),ui.colorBarWidget->rect().topRight());

   gradient.setColorAt(0,   Qt::blue);
   gradient.setColorAt(0.2, Qt::green);
   gradient.setColorAt(0.4, Qt::red);
   gradient.setColorAt(0.6, Qt::yellow);
   gradient.setColorAt(1,   Qt::cyan);
   palette.setBrush(QPalette::Base, gradient);

   ui.colorBarWidget->setPalette(palette);

In addition this code works in stand alone QWidget application.This is its
output:

[image: enter image description here] <http://i.stack.imgur.com/z5fc5.png>

But I can not do same thing in my design. I can do this with styleSheet

ui.colorBarWidget->setStyleSheet( "background-color: qlineargradient(
x1:0 y1:0, x2:0 y2:1, stop:0 blue, stop:1 red )" ); /* works */

but why I can not do this with QPalette.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160331/e443daf3/attachment.html>


More information about the Interest mailing list