Results 1 to 4 of 4

Thread: why triggerUpdate() is not virtual?

  1. #1
    Join Date
    Jan 2006
    Location
    Sofia, Bulgaria
    Posts
    24
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Zebra-like QListViewItems -- how to?

    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:
    Qt Code:
    1. void my_list_view::triggerUpdate() //NOTE: NOT VIRTUAL!!
    2. {
    3. int counter( 0 );
    4. for( QListViewItemIterator i( this, QListViewItemIterator::Visible ); *i; ++i, ++counter )
    5. {
    6. ( *i )->set_is_light( counter %2 );
    7. }
    8. QListView::triggerUpdate();
    9. }
    10.  
    11. my_list_view_item::paintCell( QPainter * p, const QColorGroup& cg, int colun, int width, int alignment )
    12. {
    13. QColorGroup cg2( cg );
    14. if ( is_light() )
    15. {
    16. cg2.setColor( QColorGroup::Background, cg.light() );
    17. cg2.setColor( QColorGroup::Base, cg.light() );
    18. }
    19. QListViewItem::paintCell( p, cg2, column, width, alignment );
    20. }
    To copy to clipboard, switch view to plain text mode 
    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)
    Last edited by gadnio; 11th January 2006 at 10:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Zebra-like QListViewItems -- how to?

    Try something like this:
    Qt Code:
    1. void my_list_view_item::paintCell( QPainter * p, const QColorGroup& cg, int column, int width, int alignment )
    2. {
    3. QColorGroup cg2( cg );
    4. if ( itemPos() % height() )
    5. {
    6. cg2.setColor( QColorGroup::Background, cg.light() );
    7. cg2.setColor( QColorGroup::Base, cg.light() );
    8. }
    9. QListViewItem::paintCell( p, cg2, column, width, alignment );
    10. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Sofia, Bulgaria
    Posts
    24
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: why triggerUpdate() is not virtual?

    this is not quite useful if i have items with different height()'s
    i have tried the following, but no success at all:
    Qt Code:
    1. static bool enlighten( false );
    2. void my_list_view_item::paintCell(...)
    3. {
    4. if ( column == listView()->columns() - 1 )
    5. {
    6. if ( enlighten )
    7. {
    8. //"white stripe"
    9. }
    10. else
    11. {
    12. //"dark strpe"
    13. }
    14. enlighten = !enlighten;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    (things get messy when expanding/closing items, when hiding items and on partial redraws)

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: why triggerUpdate() is not virtual?

    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 18:50
  2. Cost of pure virtual
    By ShaChris23 in forum General Programming
    Replies: 4
    Last Post: 4th November 2007, 19:20
  3. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 15:13
  4. Compiling error
    By vfernandez in forum Newbie
    Replies: 2
    Last Post: 9th March 2007, 22:02
  5. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 17:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.