View Full Version : QTreeView selection Style ?
jpujolf
2nd March 2009, 14:15
Anybody knows how to make selected cell in a row look like this with StyleSheets ? I'm been trying but no success...
I'm using QTreeViews, with row selection. A very thin dotted line appears by default, but I want a more evident rectangle.
talk2amulya
2nd March 2009, 14:37
try:
QTreeView::item:selected
{
background-color:transparent;
color:blue;
}
jpujolf
2nd March 2009, 14:59
Thanks, but doesn't work.
ALL cells on the row are in blue, because selection is QAbstractItemView::SelectRows.
I only want the one is selected and focused ( Qt paints a thin dotted line around it ).
talk2amulya
2nd March 2009, 15:02
that is possible in QTableView
jpujolf
2nd March 2009, 15:34
that is possible in QTableView
I haven't tested it, but if you make this call :
setSelectionBehavior (QAbstractItemView::SelectRows );
Is still working ? Anyway, I'm forced to use QTreeView, cannot use QTableView. As I show in the capture screen, my data has a tree structure.
aamer4yu
2nd March 2009, 18:33
Hi, Will delegates suit you ?
you can try the following -
class ItemDelegate : public QItemDelegate
{
public:
void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QItemDelegate::paint(painter,option,index);
if(option.state & QStyle::State_HasFocus)
{
painter->save();
QPen pen = QPen(Qt::green);
pen.setWidth(2);
painter->setPen(pen);
painter->drawRect(option.rect.adjusted(1,1,-1,-1));
painter->restore();
}
}
};
Just set it on your treeview / tree widget.
It works ,, I tested it..
May be you can try with style sheet too... try focus instead of selected.
jpujolf
3rd March 2009, 07:49
As usual, I've made a KISS ( Keep It Simple Stupid ), so setting this in the styleSheet works like a charm !!
QTreeView::item:focus
{
background-color:transparent;
color:blue;
}
Thanks a lot !!
papius_vtualetius
20th January 2011, 12:01
jpujolf, how did you make root elements to draw different background?
jpujolf
20th January 2011, 12:15
I've done it by overloading QVariant QAbstractItemModel::data ( const QModelIndex & Index, int Role ) const
with role Qt::BackgroundRole. Not all can be done with stylesheets...
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.