[Interest] Default delegate with QTableView and QSqlTableModel

Mark Brand mabrand at mabrand.nl
Thu Mar 28 12:19:27 CET 2013



> > So my question is: is it possible to change the default type for
> > INTEGER to QVariant::Int from qlonglong?
> > Or even better, is it possible to change that for just a selected
> > column in the QSqlTableModel?
> > That would be a clean solution.
> > 
> > Another good solution would be to set a delegate/editor for qlonglong,
> > but do we have a better way than creating a subclass of QItemDelegate
> > or QItemEditorCreatorBase with 50+ lines of code?
> > 
> > tr3w
> 
> Well, I think the issue is that QSpinBox is limited to an int range, so
> it can't be used for qlonglong.
> 
> For your case, I think I would make a simple proxy model based on
> QIdentityProxyModel that adapts the data type from longlong to int when
> possible and where desirable. That should only take a couple of loc. I
> don't think it will be easy to coax the driver into using int instead of
> longlong.
> 

Actually, the driver is probably doing something pretty reasonable. SQLite 
itself has a rather unsual (if not unique) type system. The delegate and proxy 
workarounds have already been mentioned. Another possibility is a subclass of 
your model that adjusts the type.

Mak



More information about the Interest mailing list