QSortFilterProxyModel subclass for readonly columns columns with checkboxes and password columns

From Qt Wiki
Revision as of 16:38, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

QSortFilterProxyModel subclass for readonly, checkboxes and password columns

When you try to use a QTableView with QSql*** model classes, it is difficult to make boolean column appear as check boxes or make columns readonly.

This is a QSortFilterProxyModel subclass that is designed to be generic enough to easily accomplish these tasks. It also includes some primitive ‘password’ field support.

If you want to add a check box to a model but you don’t want to use a boolean field in the source model to keep track of the value of the check box, you can take a look at CheckableProxyModel.

You should create three

QList<int>

container classes, one each to hold the column indexes of the fields you want checkboxes for, to be displayed as passwords, or be readonly.

  • NOTE: If you are using a QSqlRelationalTableModel, there are issues with the QSortFilterProxyModel (the combo box). To resolve that, I have created another wiki article about a QSqlRelationalDelegate subclass (mySqlRelationalDelegate) that you can use.
  • EDIT: Since I discovered another problem with the handling of NULL values, I have added the possibility to this class to address it.

Usage

The subclass usage is as follows:

Code

So here is the code:

checkablesortfilterproxymodel.h

checkablesortfilterproxymodel.cpp

Categories: