Results 1 to 2 of 2

Thread: How to dispay an icon in the first column of QTreeView

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow How to dispay an icon in the first column of QTreeView

    Hi!

    Here is what i need: Display an icon in the first column of QTreeView. Icon should remain at 1st column even if the column is dragged to some other position.


    Here is what i did: Inherited from QAbstractItemDelegate to create a GItemDelegate whose paint method has something like this
    Qt Code:
    1. QTreeView *t_view = qobject_cast<QTreeView*>(parent());
    2. if(t_view)
    3. if(t_view->header()->visualIndex(index.column()) == 0){
    4. value = model->data(index, Qt::DecorationRole);
    5. pixmap = decoration(opt, value);
    6. pixmapRect = (pixmap.isNull() ? QRect(0, 0, 0, 0):QRect(QPoint(0, 0), option.decorationSize));
    7. }
    To copy to clipboard, switch view to plain text mode 

    New problem: Documentation for header()->visualIndex say that
    Hidden sections still have valid visual indexes
    Hence, if first column is hidden icon is not visible.
    -----------------------------------------------------------
    So the question is how to (quickly) determine the first visible column of QTreeView in GItemDelegate.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to dispay an icon in the first column of QTreeView

    I suggest iterating over all sections from 0 to header()->count() and check for each section wether it's visible. If it is visible, show the icon. If it is not visible, go on with the next section.

Similar Threads

  1. Differentiate the icon and text in a QTreeView column
    By gmat4321 in forum Qt Programming
    Replies: 0
    Last Post: 25th February 2009, 16:38
  2. QTreeView: make root decoration appear on visual column 0
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2008, 03:36
  3. QTreeView Fixed column & QTableView
    By jpujolf in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2008, 10:35
  4. Fixed Column in QTreeview
    By ormonde in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 08:49
  5. QTreeView - different icon sizes on sublevels?
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 18th January 2008, 16:34

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.