Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 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?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 595 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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
              }
          }
      });
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved