Custom qtreeview



  • I need some guidance here on how to possibly implement the following custom
    qtreeview.

    Suppose I have QTreeView with say 4 columns

    @A
    B
    |-C checkbox checkbox checkbox
    |-D checkbox checkbox checkbox
    E
    F
    |-G checkbox checkbox checkbox
    |-H checkbox checkbox checkbox
    |-I checkbox checkbox checkbox
    |-J checkbox checkbox checkbox@

    1.I want to be able to say click on an item in the first column and allow it
    to be edited to another name EXCEPT if is A,B,E or F (any top level item) but any other item
    such as C,D,G,H, etc. can be edited to a new name. Additionally, I want to be able to click
    on a checkbox and change its setting.

    1. How can I get the pointer back to my derived QTreeViewItem so that i can then
      apply them to the underlying data?

    Thanks for any help.



  • If you can use QTreeWidget the following should work. QTreeWidget is a subclass of QTreeView so everything the widget can, the view also is able to but maybe with a bit more programming effort.

    You can use
    @
    item = new QTreeWidgetItem();
    tree->addItem(item);
    @

    to add a new item to the tree. By giving a parent you can build your hierarchy. After that you can set your own widget for the item with
    @

    tree->setItemWidget(item, 0, new MyWidget());
    @

    I am not sure which methods you can use with the QTreeView but as I wrote before you can write all of them yourself if necessary.

    You can get you widget back with

    @
    QList<QTreeWidgetItem *> selected = tree->selectedItems(); //or if you want to use the mouse pos
    tree->itemAt(x, y);
    @

    EDIT
    You use the flags to make the items editable or whatever:

    @
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    @

    Be aware that for example if you parent item is not enabled you cannot select the child for example.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.