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();
    10.  
    11. model->setQuery(*qry);
    12.  
    13. ui->tableView->setModel(model);
    14.  
    15.  
    16. conn.connClose();
    17. qDebug() << (model->rowCount());
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    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
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    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.

    Cheers,
    _

Similar Threads

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

Tags for this Thread

Bookmarks

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.