PDA

View Full Version : QTableWidget customize row colour



THRESHE
27th February 2008, 16:44
Hi everyone
I've encountered a problem while using sheets with Qt Designer. I try to set color for a row as a gradient like this

QTableWidget
{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #ffffff, stop: 1 #ecf9ff);
}
But instead of painting a row with this gradient it paints all rows from top to bottom with it like it is a solid piece :(

wysota
27th February 2008, 21:20
Well... if you ask the stylesheet to paint all widgets inheriting QTableWidget in such a way, it does exactly so. You didn't mention you wanted items or so... and besides, you can't style items in Qt 4.3 and older.

THRESHE
28th February 2008, 11:52
So it is impossible to fill each row of table widget with gradient ? :confused:

wysota
28th February 2008, 14:22
I didn't say that. Your stylesheet is incorrect. If you want to do it with stylesheets, you'll need Qt 4.4. If you want to do it without stylesheets - provide a custom delegate and do the painting there.

THRESHE
28th February 2008, 14:30
It's funny that it is possible to customze aternate row colour with gradient while it isn't possible to do it for ordinary row.

I think I wont be able to use delegates for this because I don't know how to implement them :(

wysota
28th February 2008, 14:49
I think I wont be able to use delegates for this because I don't know how to implement them :(

It's really easy, try it. Subclass QItemDelegate and reimplement paint(). Fill the rectangle specified with your gradient and then call the base class implementation of drawDisplay(). You'll have something to start with...

THRESHE
28th February 2008, 14:56
It's really easy, try it. Subclass QItemDelegate and reimplement paint(). Fill the rectangle specified with your gradient and then call the base class implementation of drawDisplay(). You'll have something to start with...
Thanks I'll try it ;)