PDA

View Full Version : Impossible to get correct widget background color



croscato
6th June 2009, 11:27
Hi all.

Here is what I want to do:
1) In paintEvent a make some draws and text in the widget using a QPainter object

2) Then a want to give it a perfurated effect. I'm thinking in this solution


QBrush brush(this->palette().background().color(),Qt::Dense4Pattern);
painter.fillRect(0, 0, this->width() - 1, this->height() - 1, brush);

The problem is the that palette().background().color() doesn't return the right widget backgroung color. It returns an aproximate light color.

Am I missing something?

wysota
7th June 2009, 08:52
What is the widget? Maybe you should use base() instead of background()?

croscato
8th June 2009, 17:13
I tryed base() too with no success.

My widget is a sub-class of QPushButton, like this:

class QIscButton: public QPushButton

I don't know if it's relevante but I'm using Slackware 12.2, with KDE 4.2.3 and the Qt version is 4.5.1.

Thanks.

croscato
8th June 2009, 19:40
I think I know what the problem is. Looking more carefully at the widgets background in my system I could see that In KDE using the Oxygen theme the widgets background aren't a solid color but a gradient. With colors that are close to each other, what makes the gradient almost imperceptible.

Now my question is. How can a manage to get a QGradient that matches the KDE theme (Oxygen) without hard-code with?

Thanks.

wysota
8th June 2009, 21:42
How can a manage to get a QGradient that matches the KDE theme (Oxygen) without hard-code with?

You can try the button() role of the palette. But I can't guarantee this will work. Otherwise you have to use QStyle API.