gadnio
11th January 2006, 08: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)
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)