Results 1 to 4 of 4

Thread: QTableview, checkboxes and SQlite

  1. #1

    Default 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:
    Qt Code:
    1. void myClass::on_pushButton_clicked()
    2. {
    3. Widget conn;
    4. QSqlQueryModel * model = new QSqlQueryModel();
    5. conn.connOpen();
    6. QSqlQuery* qry = new QSqlQuery(conn.db);
    7. qry->prepare("select * from plan where username='"+username_temp+"'");
    8. qry->exec();
    9. QTextStream (stdout) << qry->lastQuery();
    11. model->setQuery(*qry);
    13. ui->tableView->setModel(model);
    16. conn.connClose();
    17. qDebug() << (model->rowCount());
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android

    Default 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.

  3. #3

    Default 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?

  4. #4
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Unix/X11 Windows

    Default 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.


Similar Threads

  1. Bigger checkboxes in QTableView?
    By qlands in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2012, 12:13
  2. No checkboxes are displayed in a QTableView
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2010, 17:28
  3. Unsolicited checkboxes in QTableView
    By MattPhillips in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2009, 21:44
  4. QTableView and checkboxes
    By ibergmark in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 15:20
  5. Replies: 2
    Last Post: 23rd February 2008, 01:58

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.