Results 1 to 4 of 4

Thread: [Qt 4.x] Highliting rows in a QTreeView

  1. #1
    Join Date
    Jan 2006
    Posts
    33
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11

    Default [Qt 4.x] Highliting rows in a QTreeView

    Hi,

    I want to highlight every other row in a QTreeView by changing the background colour for every ohter row.
    |one |
    |two|
    |three|
    |four|

    I have done this in qt3 by reimplementing

    Qt Code:
    1. QListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
    2. int column, int width, int alignment )
    To copy to clipboard, switch view to plain text mode 
    I have a custom model which I feed into the view.

    I just don't find an appropriate pointer where to do it.
    In repaint of the view?
    Or do I have to use a custom style?

    Thanks,

    Moppel
    Last edited by Moppel; 9th March 2006 at 22:06.

  2. #2
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.x] Highliting rows in a QTreeView

    try myTreeView->setAlternatingRowColors(true);

  3. #3
    Join Date
    Jan 2006
    Posts
    33
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: [Qt 4.x] Highliting rows in a QTreeView

    cool, that works! Completely missed that in the doc. Embarrassing!
    Thanks.
    Seems to have been a so often reimplemented feature that the trolls put it in there API then.

    Right, but now, if I want to go further and highlight a row or a even a cell depending on the content of the row/cell.
    How can I do this?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Qt 4.x] Highliting rows in a QTreeView

    Use different roles from the model. If it's not enough, provide a custom delegate for the view.

Similar Threads

  1. Replies: 4
    Last Post: 26th September 2011, 12:02
  2. QTreeView and multi-select of rows
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2008, 02:32
  3. Fetching rows in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 18:17
  4. QTreeView rows (items) StyleSheet
    By Kostanev in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2007, 10:36
  5. QTreeView rows editable
    By Pesho in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2007, 13:19

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.