Menu

Modify elements TreeWidget

Anonymous
2021-02-23
2021-02-24
  • Anonymous

    Anonymous - 2021-02-23

    Hello,
    as I didn't see it in the manual:
    Is there no way to modify elements from a treeview other than deleting it?

    The background is that I plan do sort messages I get by byte into a tree structure.
    I get messages quite fast, they alway repeat and only show some differences in some data fields. I plan to display it by a treeview as it looks matching for my purpose.
    So I don't want to add elements to the view, I want to modify existing ones. Is there a good way for this? From the C++-QT i remember this as possible..

    Thanks!

     
  • Stefan Zieker

    Stefan Zieker - 2021-02-23

    Hi,

    yes you can modify elements. Here is an example:

    var rootItem = UI_treeWidget.invisibleRootItem();
    
    var treeItem1 = UI_treeWidget.createScriptTreeWidgetItem();
    treeItem1.setText(0, "value1");
    treeItem1.setItemIcon(0, scriptFile.createAbsolutePath("icons/openfolder.gif"));
    treeItem1.setText(1, "value2");
    treeItem1.setItemIcon(1, scriptFile.createAbsolutePath("icons/folder.gif"));
    rootItem.addChild(treeItem1);
    

    To modify the elements later you have to store them or you can use the following functions to iterate over the elements:

    var item = UI_treeWidget.topLevelItem(index)
    var itemBelow = UI_treeWidget.itemBelow(item)
    var item2 = UI_treeWidget.itemAbove(itemBelow)

     

    Last edit: Stefan Zieker 2021-02-23
  • Anonymous

    Anonymous - 2021-02-24

    Thank you for the quick answer!
    I already saw this in the manual. What I'm missing is a command to get to a child. The only command I saw is "takeChild", but this one removes the item.
    Like the command ScriptTreeWidgetItem* parent (void) for a child.

     

Anonymous
Anonymous

Add attachments
Cancel