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. QCheckBox in QTableView: how to avoid selection menu
Forum Updated to NodeBB v4.3 + New Features

QCheckBox in QTableView: how to avoid selection menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 663 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I put checkboxes in a column of my QTableView. For that column I set the following flags: Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEditable; and in the data() function I handled the CheckStateRole:

    case Qt::CheckStateRole:
        switch (index.column())
        {
            case COL_CHECKBOX: return item.enabled ? Qt::Checked : Qt::Unchecked;
            default: return QVariant();
        }
    

    It works, but when I try to (un)flag the checkbox it shows a menu with "True" and "False" items. It's useless for me... I just want to (un)check the QCheckBox with one click. Is there a way to do this?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Looks like you return something for COL_CHECKBOX and Qt::EditRole (or Qt::DisplayRole)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Looks like you return something for COL_CHECKBOX and Qt::EditRole (or Qt::DisplayRole)

        M Offline
        M Offline
        Mark81
        wrote on last edited by Mark81
        #3

        @Christian-Ehrlicher Yes, I return something only for Qt:EditRole in order to read data from my code. Removing it, it now activate a line edit to write something... still no way to click the checkbox!

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mark81 said in QCheckBox in QTableView: how to avoid selection menu:

          Qt::ItemIsEditable

          I'm not sure but can you try to remove this for COL_CHECKBOX?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Mark81 said in QCheckBox in QTableView: how to avoid selection menu:

            Qt::ItemIsEditable

            I'm not sure but can you try to remove this for COL_CHECKBOX?

            M Offline
            M Offline
            Mark81
            wrote on last edited by
            #5

            @Christian-Ehrlicher said in QCheckBox in QTableView: how to avoid selection menu:

            I'm not sure but can you try to remove this for COL_CHECKBOX?

            Removing the Qt::ItemIsEditable from the checkbox column just prevent any further changes to the cell's value.

            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