QTableview, checkboxes and SQlite
Hello to each and everyone, I'm trying to put in a tableview a checkbox which should be linked to a value in the db of SQlite, the program select first a query and insert data into the table but I want to add a column with a checkbox for each record found in the db. How can i add it to the QSqlQueryModel and Qtableview already created by QTcreator?
Thank you so much
This is my code:
Code:
void myClass::on_pushButton_clicked()
{
Widget conn;
conn.connOpen();
qry->prepare("select * from plan where username='"+username_temp+"'");
qry->exec();
model->setQuery(*qry);
ui->tableView->setModel(model);
conn.connClose();
qDebug() << (model->rowCount());
}
Re: QTableview, checkboxes and SQlite
You have to create your own data model inheriting from QSqlTableModel.
Reimplement flags() method and use Qt::ItemIsUserCheckable for the column with the checkbox.
Reimplement data() and setData() to manage the role Qt::CheckStateRole properly for the column with the checkbox.
Re: QTableview, checkboxes and SQlite
Ok, I'm trying to do that, I have the delegate but I don't know how to link with the database. Can you give me an example?
Re: QTableview, checkboxes and SQlite
nix suggested to create a subclass of the model you are currently using, so that you can either make one of the existing columns checkable or add a column.
Another option is to use a proxy model.
Delegate has nothing to do with that.
Cheers,
_