Results 1 to 5 of 5

Thread: QTreeView / QTreeWidget

  1. #1
    Join Date
    May 2006
    Posts
    9
    Thanks
    1

    Default QTreeView / QTreeWidget

    Hi,

    I am trying to use QTreeView or QTreeWidget as a property setting tool.

    I would like to have two columns, one for the property name and one for the setting/value.
    In the property name column I want a tree structure with categories (as parents to properties) and properties.

    I only want to be able to edit the second column (the setting/value) not the column with the name of the property.

    Until now I have not found a way to make only the second column editable.

    Can anyone help me? Either with a solution to the above problem or a completely different solution using a different widget.

    Morty

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView / QTreeWidget

    I'm not sure if QTreeWidget is the way to go for something like this. A quick look at QTreeWidgetItem docs tells me that you can only change flags for the whole QTreeWidgetItem, not for individual columns. As a QTreeWidgetItem represents the whole row (both columns in your situation), I can't see any way to set only one of the columns editable. But with QTreeView that should be no problem. Just make sure you return Qt::ItemIsEditable only for appropriate indexes in overridden QAbstractItemModel::flags() method.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    9
    Thanks
    1

    Default Re: QTreeView / QTreeWidget

    I'm not sure if I was specific enough explaining the problem.

    I can make the QTreeView work setting the flag Qt::ItemIsEditable for an item. The problem then is that all columns for the item is editable. I only want the second column editable not the item in the tree (first column).

    Morty

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView / QTreeWidget

    I still think I did understand it fine..

    I meant something like this:
    Qt Code:
    1. Qt::ItemFlags YourModel::flags(const QModelIndex& index) const
    2. {
    3. switch (index.column())
    4. {
    5. case 0: return Qt::ItemIsSelectable | Qt::ItemIsEnabled; // non-editable column
    6. case 1: return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; // editable column
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    May 2006
    Posts
    9
    Thanks
    1

    Default Re: QTreeView / QTreeWidget

    Thanks jpn.

    I didn't quite understand how to implement your suggestion at first. Then I tried the Simple Tree Model Example from Qt Assistant with your suggestion implemented.

    I can now see that QTreeView can do what I want, now I just have to understand it...

    Morty.

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  3. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24
  4. QTreeWidget problem!!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2006, 11:47
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.