Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Can QTreeWidget have checkboxes at top level if there are no sub-nodes for that parent element?
Forum Update on Monday, May 27th 2025

Can QTreeWidget have checkboxes at top level if there are no sub-nodes for that parent element?

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 3 Posters 651 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.
  • A Offline
    A Offline
    ACollins
    wrote on last edited by
    #1

    I create an item at the top level with the following code.

    l1 = QTreeWidgetItem(["String A", "String B", "String C","String D"])
    l1.setFlags(l1.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
    l1.setTextAlignment(2, QtCore.Qt.AlignRight)
    

    Everything works fine and the checkbox shows up but only if there are sub-nodes, i.e. child elements. For some top level nodes there are no child elements but I need a checkbox with them. Is that possible? Thanks.

    jsulmJ 1 Reply Last reply
    0
    • A ACollins

      I create an item at the top level with the following code.

      l1 = QTreeWidgetItem(["String A", "String B", "String C","String D"])
      l1.setFlags(l1.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable)
      l1.setTextAlignment(2, QtCore.Qt.AlignRight)
      

      Everything works fine and the checkbox shows up but only if there are sub-nodes, i.e. child elements. For some top level nodes there are no child elements but I need a checkbox with them. Is that possible? Thanks.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ACollins Is it same if you remove Qt.ItemIsTristate ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ACollins
        wrote on last edited by
        #3

        @Denni-0 The key was the third line: treItem_1.setCheckState(3, Qt.Unchecked)

        I put that in and it started working. I thought it would default to the unchecked state but guess not. Thanks for the tip.

        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