[Interest] Default delegate with QTableView and QSqlTableModel

Tr3wory tr3w at freemail.hu
Thu Mar 28 14:42:14 CET 2013


On Thu, Mar 28, 2013 at 11:18 AM, André Somers <andre at familiesomers.nl> wrote:
> Op 28-3-2013 11:13, Tr3wory schreef:
>
>> Technically you are right, on the other hand it is really counter
>> intuitive to not have a default editor for qlonglong if the qsqlite
>> driver gives me that for every integer by default.
>> It would be a perfect solution to me if I could change the default
>> type, but the
>> QSqlDatabase::setNumericalPrecisionPolicy(QSql::LowPrecisionInt32)
>> does not do the trick (and obviously it's not a general solution).
>>
>> 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.
>
> André
>

Thank you for the tip, the QIdentityProxyModel looks promising.

And yes, the QSpinBox is not good enough for qlonglong in general.
What about a QLineEdit with a proper input mask?

tr3w



More information about the Interest mailing list