[Qt-interest] set widget background to color gradient using style sheet.
Oliver Demetz
forenbeitraege at oliverdemetz.de
Tue Jun 9 15:34:42 CEST 2009
Hi all,
I want to report a strange behaviour of my qt app:
My main widget consists of a few small buttons and one big
QGraphicsView. The view spans nearly the whole height of my widget and
has a fixed 4:3 aspect ratio.
So if the widget has height, say 500px, then the view is centered in it
with a padding of about 20 px on top and bottom.
Now the simple stylesheet:
MainWidget {
background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #000000,
stop:1 #ffffff);
}
*Independently* of how I manage the layout of this widget - be it a
QLayout or be it a manual layout - the result is not what one would expect:
There is *not one linear gradient* going from top left to bottom right!
Instead, qt splits the widget into 5 regions and paints a *new* gradient
in each region:
first region is the qgraphicsview itself, no background is visible and
thus no gradient is painted, correct.
second area is the following rect:
If the main widget has height h and width w we get:
rect (0,0,w,padding)
third:
rect(0,padding, [free space left of the view], h-2*padding)
fourth:
rect(view.rect().right(), padding, [free space right of view], h-2*padding)
fifth:
rect(0, padding + view.rect().height(), w, padding)
In each of these rects, a new qlineargradient is painted!!!
At first I thought that this problem has to do with the fact that the
graphicsview is openGL-powered. But I tried to write a test case and
found out that the error also occurs without opengl set as viewport.
It seems that it has to do with the thickness of the padding. if this
passing becomes large enough, the gradient is painted correctly.
Thank you for your ideas in advance,
best regards,
Oliver
More information about the Qt-interest-old
mailing list