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 and Checkable data
Qt 6.11 is out! See what's new in the release blog

QTableView and Checkable data

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 14.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi. I want display QCheckBox in the first Column of the QTableView. How can I set userChaeckable flag? Сan be an example.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      see the class QxtTableWidgetItem "LIBQXT":http://libqxt.org/

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Your model should include Qt::ItemIsUserCheckable in the flags that are returned for the indexes in the first column.

        Are you using a QTable View or a QTable Widget?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          I'm using QTableView, can you write an example?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You have to return the Qt::ItemIsUserCheckable as (one of your) flags from the flags() method of your model, and return a valid value in your data() method for the Qt::CheckStateRole. What model are you using?

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Hello

              I do that in the model :
              @...
              index = (modelTab)->index(row, col, QModelIndex());
              value =(((modelTab)->data(index)).toString());

              modelTab->itemFromIndex(index)->setCheckable(true);

              if (value=="true") {
              modelTab->item(row, col)->setCheckState(Qt::Checked);
              }@

              with :
              @QStandardItemModel *modelTab@

              Fred

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Then just call setCheckable(true) on your QStandardItem for the first column.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  it is clearer like that, thanks VolKer

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Ok, I set setCheckable(true) for first column and how I get namber or index of checked?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Use the itemChanged signal from QStandardItemModel.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #11

                        [quote author="Sidny Sho" date="1332273888"]Ok, I set setCheckable(true) for first column and how I get namber or index of checked?[/quote]

                        UseQStandardItemModel::findItems() or QAbstractItemModel::match().

                        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