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. QTableView: show checkbox, but keep it disabled
QtWS25 Last Chance

QTableView: show checkbox, but keep it disabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 3.3k 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.
  • HunterMetcalfeH Offline
    HunterMetcalfeH Offline
    HunterMetcalfe
    wrote on last edited by
    #1

    Hi all,

    I'm working with my implementation of QAbstractTableModel, which to state upfront, I have no issues with the ability to add checkbox columns to my QTableView.

    My question, rather- are you able to show the checkboxes such that an individual can see them, see their state, but not interact? Think - a signed in user doesn't have the permissions to change the value, but has the ability to read it.

    I was hoping that under Qt::ItemFlags there would be an ItemIsDisabled like ItemIsEnabled, but I don't see anything in 5.9.4.

    Any tips or tricks would be greatly appreciated!

    Thank you

    Pl45m4P 1 Reply Last reply
    0
    • HunterMetcalfeH HunterMetcalfe

      Hi all,

      I'm working with my implementation of QAbstractTableModel, which to state upfront, I have no issues with the ability to add checkbox columns to my QTableView.

      My question, rather- are you able to show the checkboxes such that an individual can see them, see their state, but not interact? Think - a signed in user doesn't have the permissions to change the value, but has the ability to read it.

      I was hoping that under Qt::ItemFlags there would be an ItemIsDisabled like ItemIsEnabled, but I don't see anything in 5.9.4.

      Any tips or tricks would be greatly appreciated!

      Thank you

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @HunterMetcalfe

      Are you using delegates?
      Can't you just chkBx->setEnabled(false) these checkboxes?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • HunterMetcalfeH Offline
        HunterMetcalfeH Offline
        HunterMetcalfe
        wrote on last edited by
        #3

        @Pl45m4

        I'm not using delegates for my checkboxes I'm curious to know more in particular.
        I'm setting the flag 'ItemIsCheckable' on a certain column in the reimplemented QAbstractTableModel::flags function. I handle the value of the checkbox through a flag within the structure populating the other columns, which is populated when QAbstractTableModel::data and QAbstractTableModel::setData are called. I believe my solution is going to be to change my reimplemented QAbstractTableModel::setData function to add a flag to essentially ignore user input, hence retaining the original state.

        Pl45m4P 1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

          Hey, I can't find any flag named 'ItemIsCheckable', only ItemIsUserCheckable, which can control the interacting from users, exactly as you asked.
          It might not look like disabled, but users cannot check or uncheck without this flag.
          P.S. disabled == not enabled, so: without ItemIsEnabled == item disabled.

          1 Reply Last reply
          2
          • HunterMetcalfeH HunterMetcalfe

            @Pl45m4

            I'm not using delegates for my checkboxes I'm curious to know more in particular.
            I'm setting the flag 'ItemIsCheckable' on a certain column in the reimplemented QAbstractTableModel::flags function. I handle the value of the checkbox through a flag within the structure populating the other columns, which is populated when QAbstractTableModel::data and QAbstractTableModel::setData are called. I believe my solution is going to be to change my reimplemented QAbstractTableModel::setData function to add a flag to essentially ignore user input, hence retaining the original state.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @HunterMetcalfe

            Your way is already the easiest one. ItemIsUserCheckable turns your item into a checkbox. So use a combination of ItemIsEnabled and ItemIsUserCheckable, as also suggested by @Bonnie . If you take or don't set the enabled-flag, your item still has a checkBox, but you can not interact with it.

            https://doc.qt.io/qt-5/qt.html#ItemFlag-enum


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            B 1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @HunterMetcalfe

              Your way is already the easiest one. ItemIsUserCheckable turns your item into a checkbox. So use a combination of ItemIsEnabled and ItemIsUserCheckable, as also suggested by @Bonnie . If you take or don't set the enabled-flag, your item still has a checkBox, but you can not interact with it.

              https://doc.qt.io/qt-5/qt.html#ItemFlag-enum

              B Offline
              B Offline
              Bonnie
              wrote on last edited by Bonnie
              #6

              @Pl45m4
              Sorry to say this but that's not I meant.

              As I tested, ItemIsUserCheckable flag doesn't turn the item into a checkbox, it just controls whether user can check / uncheck the checkbox if there is one.
              Whether there will be a checkbox is determined by the value of data(Qt::CheckStateRole) is valid or not.

              So if the item has ItemIsEnabled flag and no ItemIsUserCheckable flag, and data(Qt::CheckStateRole) returns a valid value, then it will have a checkbox. The item is enabled, but the user cannot change the check state by clicking the checkbox.

              If the item has no ItemIsEnabled flag, then no matter it has ItemIsUserCheckable flag or not, the user cannot change the check state, because it is disabled.

              Pl45m4P 1 Reply Last reply
              1
              • B Bonnie

                @Pl45m4
                Sorry to say this but that's not I meant.

                As I tested, ItemIsUserCheckable flag doesn't turn the item into a checkbox, it just controls whether user can check / uncheck the checkbox if there is one.
                Whether there will be a checkbox is determined by the value of data(Qt::CheckStateRole) is valid or not.

                So if the item has ItemIsEnabled flag and no ItemIsUserCheckable flag, and data(Qt::CheckStateRole) returns a valid value, then it will have a checkbox. The item is enabled, but the user cannot change the check state by clicking the checkbox.

                If the item has no ItemIsEnabled flag, then no matter it has ItemIsUserCheckable flag or not, the user cannot change the check state, because it is disabled.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #7

                @Bonnie said in QTableView: show checkbox, but keep it disabled:

                As I tested, ItemIsUserCheckable flag doesn't turn the item into a checkbox, it just controls whether user can check / uncheck the checkbox if there is one.

                Haven't tested myself, but AFAIK there is this flag which automatically adds a checkBox to your item. Thought, this was ItemIsUserCheckable, but could be wrong...

                Edit: It works for QListWidget items... Though it will work with QTableWidget / QTableView as well, but apparently the flag is handled differently in both models / views


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                JonBJ 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @Bonnie said in QTableView: show checkbox, but keep it disabled:

                  As I tested, ItemIsUserCheckable flag doesn't turn the item into a checkbox, it just controls whether user can check / uncheck the checkbox if there is one.

                  Haven't tested myself, but AFAIK there is this flag which automatically adds a checkBox to your item. Thought, this was ItemIsUserCheckable, but could be wrong...

                  Edit: It works for QListWidget items... Though it will work with QTableWidget / QTableView as well, but apparently the flag is handled differently in both models / views

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Pl45m4

                  Haven't tested myself,

                  No, @Bonnie is correct on this one (QTableView at least) :) The data(Qt::CheckStateRole) determines whether there is a checkbox, the ItemIsUserCheckable determines whether the user can change its state (only useful if it has a checkbox).

                  Pl45m4P 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Pl45m4

                    Haven't tested myself,

                    No, @Bonnie is correct on this one (QTableView at least) :) The data(Qt::CheckStateRole) determines whether there is a checkbox, the ItemIsUserCheckable determines whether the user can change its state (only useful if it has a checkbox).

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @JonB

                    I could swear, I once just set the flag without changing any role and it changed the item (added a checkBox). But good to know :)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    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