PDA

View Full Version : How to draw LinearGradient background for QComboBox‘s item when focused?



zimang
2nd December 2010, 10:30
Hi, guys:

I want to draw a LinearGradient background for QCombobox item when item was focused.

I can't use CSS do it.

Now I use the code like this: but it seems like that it LinearGradiented for all items as one;


QLinearGradient linearGradient2(0, 0, 0, 100);
linearGradient2.setColorAt(0, QColor(132, 132, 132, 0));
linearGradient2.setColorAt(0.96, QColor(132, 132, 32, 255));

p.setBrush(QPalette::Highlight, QBrush(linearGradient2));
this->setPalette(p);


Thanks a lot!

Added after 15 minutes:

The Qt deal with the 1st item, 2nd .. .. as a pic. I just want to do each item like the 1st one.
1:
http://blog.chinaunix.net/photo/94700_101202172658.jpg
2:
http://blog.chinaunix.net/photo/94700_101202172709.jpg
3:
http://blog.chinaunix.net/photo/94700_101202172719.jpg

bothorsen
2nd December 2010, 11:04
It sounds like you need to write a QStyle subclass for this. In there, you can paint the widget in any way you want. For all other widgets and parts, you can let the base class handle it.

zimang
2nd December 2010, 12:27
So it means I can't implement it by QPalette? I repaint the label by paintEvent(), but can't repaint the popup menu.