Results 1 to 7 of 7

Thread: Highlight row in treeview

  1. #1
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Highlight row in treeview

    Is it possible to highlight a row in a treeview?

    I tried doing this by trying to make my own QItemDelegate, but I have absolutely no idea how to do it :s

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Highlight row in treeview

    By saying "highlight a row" do you mean that the whole row should be selected (but not a single cell)? If yes, then use
    Qt Code:
    1. yourTableView->setSelectionBehavior(QAbstractItemView::SelectRows).
    To copy to clipboard, switch view to plain text mode 

    Sorry if I misunderstood.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: Highlight row in treeview

    I'm not sure what you mean either. By default a QTreeView/QTreeWidget will allow you to highlight individual cells. If you want that to go across all cells in a row do the following

    Qt Code:
    1. treeview.setAllColumnsShowFocus(True)
    To copy to clipboard, switch view to plain text mode 

    Hopefully thats what you're looking for, otherwise you'll need to clarify. Though it doesnt sound like you'll need a delegate, thats for some seriously advanced stuff

  4. #4
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Highlight row in treeview

    Oh no, that's not what I meant, sorry.

    What I want to do is to give a background color to a specific row. I'm making a music player and I have a list of songs but I want to make clear which song is currently playing...

    Thanks in advance,
    Gillis

  5. #5
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    511
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Highlight row in treeview

    Hi, if you have a view, you probably also have a model. In Model::data (), use Qt::BackgroundRole and return the color you like.

    Ginsengelf

  6. #6
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Highlight row in treeview

    I have tried that before, but it only shows the color when you hover over the row...

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    511
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Highlight row in treeview

    You could have a look into the sources of QAbstractItemView::setAlternatingRowColors(). It is not exactly what you want, but maybe it can give you some ideas.

    Ginsengelf

Similar Threads

  1. Menu Item has no highlight
    By blackfox in forum Qt Programming
    Replies: 6
    Last Post: 24th September 2008, 12:17
  2. Replies: 1
    Last Post: 5th August 2008, 20:44
  3. Hover and Highlight QTable and QTree Items
    By VireX in forum Qt Programming
    Replies: 41
    Last Post: 18th May 2007, 21:55
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. TreeView click item not connecting
    By Big Duck in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2006, 19:38

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.