I haven’t really encountered a worked out example of this combination, which is why I decided to provide one in this post. A somewhat outdated example of how to do that is offered in the Qt FAQ.įor good results in my use-case, where I want to have check boxes that (1) are able to handle a ‘pretend boolean’ variable (a boolean that is actually an integer) from a sqlite database, and (2) are not all aligned to the extreme left of their column, you have to combine the two solutions mentioned above. In this case, the only solution seems to be to use a QStyledItemDelegate to handle the paint() function that determines how the column is visualised. But if you do that, you’ll have a quite ugly looking table, since the check boxes are all left-aligned in their column, with no obvious way to change that.This can be done by sub-classing the QSqlTableModel, and re-implementing its flags(), data() and setData() functions, as suggested here. You can use an integer variable to ‘simulate’ a boolean variable by setting it to 0(for false) or 1 (for true), but you will of course need to do a bit of extra work to make the QSqlTableModel properly treat it as a boolean (or something that can be switched on or off) in read & write operations. Sqlite databases don’t actually support boolean variables.There are two main hurdles in getting the QTableView widget to work with check boxes: This post is about how to create the interactive check boxes shown in the right-most column. ![]() What you see in the screen shot is QTableView widget that shows data that it fetches from a QSqlTableModel that interfaces with a table of a sqlite database. What I wanted to achieve was relatively simple: I wanted to have tables that fetch data from sql databases, and in which one column shows check boxes to set/unset a boolean variable. ![]() This post is on an issue that I struggled with very recently, while working on Q-SoPrA.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |