Results 1 to 2 of 2

Thread: No delegate for 1 column in QTreeView

  1. #1
    Join Date
    Apr 2006
    Location
    New Zealand
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default No delegate for 1 column in QTreeView

    Hi
    I've got a QTreeView with 3 columns and I'm using the default delegate implementation to edit the contents of the items in columns 2 and 3. But I'd like to disable the editor in column 1. What would be the easiest way to achieve this behaviour in QT 4.2.2?
    Thanks a lot
    Mario

  2. #2
    Join Date
    Dec 2006
    Posts
    9
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: No delegate for 1 column in QTreeView

    Hi,

    Before the tree view launches the editor of your delegate, for an item, it uses the
    flags method of your model implementation to check if the item can be
    edited, so you simply mustn't return the Qt::ItemIsEditable flag for the first column
    of your model.

    Here an example implementation of the flags method:

    Qt Code:
    1. Qt::ItemFlags CMyModel::flags( const QModelIndex& idx ) const {
    2.  
    3. if(! idx.isValid( ) )
    4. return Qt::ItemIsEnabled;
    5.  
    6. Qt::ItemFlags def = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    7.  
    8. if( idx.column( ) == 0 )
    9. return def;
    10.  
    11. return def | Qt::ItemIsEditable;
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ggrinder for this useful post:

    mace (17th February 2007)

Similar Threads

  1. Qt4 QTreeView vs Qt3 QListView
    By mcostalba in forum Qt Programming
    Replies: 6
    Last Post: 9th January 2007, 16:13
  2. Replies: 0
    Last Post: 10th November 2006, 14:46
  3. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 15:24
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 09:00
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 16:51

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.