[Qt-interest] boolean field checkbox QTableView
Christopher Rasch-Olsen Raa
christopher at technophile.info
Wed Feb 11 10:50:42 CET 2009
Onsdag 11 februar 2009 09:55:46 skrev Linos:
> Hello,
> I have a QTableView with a QSqlRelationalTableModel and i want the boolean
> colums to be checkboxes in display and edit, I have searching the forum but
> i have not understand the full picture here i think, i have tried two ways
> to do that:
>
> -Create a QItemDelegate subclass and reimplement the methods createEditor,
> setEditorData, setModelData and updateEditorGeometry to represent a
> checkbox on edit.
>
> -Create a QSortProxyModel subclass and reimplement flags to add a
> Qt.ItemIsUserCheckable on the boolean column an check for
> Qt::CheckStateRole in data method to reply with the boolean value of the
> column.
>
> If i use the sortproxymodel i get the checkbox in display with the correct
> values but i still see the "true, false" strings and to change the value i
> get a combobox with the values true or false.
>
> If i use the delegate i get the checkbox to edit on doble click but i dont
> see checkboxes in display mode, only my well know "true, false" strings.
>
> If i use the delegate and the sortproxymodel i get a checkbox on the left
> of the cell on display mode and when i try to change the value i see other
> checkbox at the right of the first where i can change the value, after i
> commit the change the second checkbox is gone and the left display checkbox
> shows the change.
>
> Do i have any way to have a checkbox column in display and edit (the same)
> and not see the text "true, false"?
>
> Thanks in advance.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
Hi,
I recently looked for a way to do this myself. What I had to do was create a
QItemDelegate and use that on the checkable column. Next I subclassed
QSqlTableWidget and overloaded flags() so that returned the proper flags for
that column. Next I used QTableView::openPersistentEditor() on the fields in
the checkable column to make them always display. There are some clues to be
found in the demo-applications.
Hope this helps.
--
Christopher
More information about the Qt-interest-old
mailing list