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.
well there is
or using a delegate
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.
This is controlled by the model.
You need to override the following methods:
- flags() - return the flags including Qt::ItemIsUserCheckable (only for indieces where you want to show the checkbox)
- 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
- data() - return QVariant::fromValue<int>( checked ? Qt::Checked : Qt::Unchecked );