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. QTreeView: "Auto-Checkboxes" and "Checkbox only"?
Forum Update on Monday, May 27th 2025

QTreeView: "Auto-Checkboxes" and "Checkbox only"?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.9k 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.
  • N Offline
    N Offline
    nonot1
    wrote on 11 May 2011, 18:04 last edited by
    #1

    Hello,

    Other than overriding the flags() and data(Qt::CheckState) members of my QAbstractItemModel based model, is there a way to induce QTreeView to render checkboxes (and tristate boxes) for certain columns of my model? If so, how? Can it be based on datatype returned by data(Qt::DisplayRole)?

    Secondly, when QTreeView renders a checkbox, it also seems to leave an area for text. It's even editable(!). How can just render the checkbox?

    Thank you

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 11 May 2011, 18:41 last edited by
      #2

      Hi,

      to enable the check boxes, you need the flags (Qt::ItemIsUserCheckable), If you set Qt::ItemIsEditable, it will be editable by an editfield.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nonot1
        wrote on 11 May 2011, 19:08 last edited by
        #3

        Gerolf,

        Yeah, I've got the check boxes by setting those flags on my data model.

        To clarify: I was wondering if there was a different way, since the choice of how to render a given data type would seem the responsibly of the view, not the model.

        Something like:
        @
        treeView->setColumnRenderRule(colNum1, QTextRenderRule);
        treeView->setColumnRenderRule(colNum2, QCheckboxRenderRule);
        @

        or even:

        @
        treeView->setCellRenderRule(QBool, QCheckboxRenderRule, optionalColumnNumber);
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 11 May 2011, 20:06 last edited by
          #4

          You could use a delegate, but that seems overkill. What might be a compromise, is to use a proxy model to do this. There is even one ready made available on the wiki in the snippets section...

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nonot1
            wrote on 12 May 2011, 00:30 last edited by
            #5

            Thanks, Andre. I'll take a look.

            1 Reply Last reply
            0

            1/5

            11 May 2011, 18:04

            • Login

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