View Full Version : Highlight row in treeview
supergillis
18th November 2008, 16:12
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
lyuts
18th November 2008, 17:14
By saying "highlight a row" do you mean that the whole row should be selected (but not a single cell)? If yes, then use
yourTableView->setSelectionBehavior(QAbstractItemView::SelectRows ).
Sorry if I misunderstood.
chezifresh
19th November 2008, 00:41
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
treeview.setAllColumnsShowFocus(True)
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
supergillis
19th November 2008, 09:04
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
Ginsengelf
19th November 2008, 12:17
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
supergillis
19th November 2008, 18:14
I have tried that before, but it only shows the color when you hover over the row...
Ginsengelf
20th November 2008, 08:49
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.