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 checkboxes

QTableView checkboxes

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.9k 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.
  • G Offline
    G Offline
    gatz
    wrote on last edited by
    #1

    Hello,

    I'm using QTableView to display data from db.
    There is a way to add checkboxes in front of each row, so when I check some checkboxes and I click Delete button to delete those specific rows?
    I'm having a hard time finding how to add those checkboxes.

    Thank you

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      well there is
      setCellWidget();

      or using a delegate
      http://www.bogotobogo.com/Qt/Qt5_QTableView_QItemDelegate_ModelView_MVC.php

      1 Reply Last reply
      2
      • G Offline
        G Offline
        gatz
        wrote on last edited by gatz
        #3

        I was thinking something like inserting another column on beginning, rather than replacing/modifying existing ones. But this works too in this case. Thanks
        P.S.: I'm kind of new to Qt and I find trivial things like this to be a bit overcomplicated, comparing to web development.

        raven-worxR 1 Reply Last reply
        0
        • G gatz

          I was thinking something like inserting another column on beginning, rather than replacing/modifying existing ones. But this works too in this case. Thanks
          P.S.: I'm kind of new to Qt and I find trivial things like this to be a bit overcomplicated, comparing to web development.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @gatz
          This is controlled by the model.
          You need to override the following methods:

          1. flags() - return the flags including Qt::ItemIsUserCheckable (only for indieces where you want to show the checkbox)
          2. setData() - check for the item role Qt::CheckStateRole and convert the passed variant to an int and compare it to Qt::Checked and save the data in your model
          3. data() - return QVariant::fromValue<int>( checked ? Qt::Checked : Qt::Unchecked );

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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