how to make the smalll triagle visible and clickable of the QTreeWidgetItem, even it does not have a child yet?



  • how to make the smalll triagle visible and clickable of the QTreeWidgetItem, even it does not have a child yet?
    and i want to dynamically add its child when i click on the small triangle there.


  • Moderators

    As suggested in the other thread showing a custom icon on a branchles item can be done with stylesheets.

    As for clicking on it - it is reported as a click on a column 0 of the item. All there is to do then is to check where inside the item rectangle the click occured. Something along these lines:

    connect(treeWidget, &QTreeWidget::itemClicked, [=](QTreeWidgetItem* item, int column){
        if(column == 0) {
            auto cursorPos = treeWidget->mapFromGlobal(QCursor::pos());
            if(cursorPos.x() < treeWidget->visualItemRect(item).x()) {// clicked on the branch area
                //do stuff e.g. add children to item
            }
        }
    });
    

Log in to reply
 

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