how to make the smalll triagle visible and clickable of the QTreeWidgetItem, even it does not have a child yet?
-
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 } } });