Results 1 to 9 of 9

Thread: QTreeView selection Style ?

  1. #1
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeView selection Style ?

    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.
    Attached Images Attached Images
    Last edited by jpujolf; 2nd March 2009 at 13:16. Reason: mistake

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    try:

    Qt Code:
    1. QTreeView::item:selected
    2. {
    3. background-color:transparent;
    4. color:blue;
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    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 ).

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    that is possible in QTableView

  5. #5
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    Quote Originally Posted by talk2amulya View Post
    that is possible in QTableView
    I haven't tested it, but if you make this call :

    Qt Code:
    1. setSelectionBehavior (QAbstractItemView::SelectRows );
    To copy to clipboard, switch view to plain text mode 

    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.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    Hi, Will delegates suit you ?
    you can try the following -
    Qt Code:
    1. class ItemDelegate : public QItemDelegate
    2. {
    3. public:
    4. void paint(QPainter *painter,
    5. const QStyleOptionViewItem &option,
    6. const QModelIndex &index) const
    7. {
    8. QItemDelegate::paint(painter,option,index);
    9. if(option.state & QStyle::State_HasFocus)
    10. {
    11. painter->save();
    12. QPen pen = QPen(Qt::green);
    13. pen.setWidth(2);
    14. painter->setPen(pen);
    15. painter->drawRect(option.rect.adjusted(1,1,-1,-1));
    16. painter->restore();
    17. }
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by aamer4yu; 2nd March 2009 at 17:43.

  7. The following user says thank you to aamer4yu for this useful post:

    jpujolf (3rd March 2009)

  8. #7
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [SOLVED] QTreeView selection Style ?

    As usual, I've made a KISS ( Keep It Simple Stupid ), so setting this in the styleSheet works like a charm !!

    Qt Code:
    1. QTreeView::item:focus
    2. {
    3. background-color:transparent;
    4. color:blue;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot !!

  9. #8
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QTreeView selection Style ?

    jpujolf, how did you make root elements to draw different background?

  10. #9
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView selection Style ?

    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...

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. QGraphicsLineItem - selection style
    By stefan in forum Qt Programming
    Replies: 5
    Last Post: 29th November 2010, 09:02
  3. Selection row in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2008, 22:31
  4. Replies: 1
    Last Post: 26th August 2007, 07:05
  5. Qtreeview selection highlighted problem?
    By thefisher in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2006, 09:50

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.