PDA

View Full Version : why triggerUpdate() is not virtual?



gadnio
11th January 2006, 09:37
I want to make manually drawn QListViewItems appear in "zebra-like" style, like this
Item 1 's background is colorGroup()::base()
Item 2 's background is colorGroup()::light()
Item 3 's background is colorGroup()::base()
Item 4 's background is colorGroup()::light()
(to make rows more distinguishable)
For a proper implementation of that I think the proper way of doing this is the following:


void my_list_view::triggerUpdate() //NOTE: NOT VIRTUAL!!
{
int counter( 0 );
for( QListViewItemIterator i( this, QListViewItemIterator::Visible ); *i; ++i, ++counter )
{
( *i )->set_is_light( counter %2 );
}
QListView::triggerUpdate();
}

my_list_view_item::paintCell( QPainter * p, const QColorGroup& cg, int colun, int width, int alignment )
{
QColorGroup cg2( cg );
if ( is_light() )
{
cg2.setColor( QColorGroup::Background, cg.light() );
cg2.setColor( QColorGroup::Base, cg.light() );
}
QListViewItem::paintCell( p, cg2, column, width, alignment );
}

the "is_light" property of the item dictates weather the item is drawn with colorGroup()::base() or colourGroup()::light()
How to implement such solution (or any other that may work)

jacek
11th January 2006, 13:28
Try something like this:
void my_list_view_item::paintCell( QPainter * p, const QColorGroup& cg, int column, int width, int alignment )
{
QColorGroup cg2( cg );
if ( itemPos() % height() )
{
cg2.setColor( QColorGroup::Background, cg.light() );
cg2.setColor( QColorGroup::Base, cg.light() );
}
QListViewItem::paintCell( p, cg2, column, width, alignment );
}

gadnio
11th January 2006, 15:04
this is not quite useful if i have items with different height()'s :(
i have tried the following, but no success at all:


static bool enlighten( false );
void my_list_view_item::paintCell(...)
{
if ( column == listView()->columns() - 1 )
{
if ( enlighten )
{
//"white stripe"
}
else
{
//"dark strpe"
}
enlighten = !enlighten;
}
}

(things get messy when expanding/closing items, when hiding items and on partial redraws)

axeljaeger
12th January 2006, 16:05
http://doc.trolltech.com/4.1/qabstractitemview.html#alternatingRowColors-prop