[Qt-interest] display one database column as two in QTableView

Israel Brewster israel at frontierflying.com
Mon Mar 8 21:03:15 CET 2010


On Mar 8, 2010, at 10:32 AM, Mark Brand wrote:
>> 
> 
> I would make it easier on yourself.  One possibility is to use the
> QDateTimeEdit to edit the timestamp as a single column.

That is actually the way I am doing it at the moment. However, I have had a user complain about two aspects of this approach:

1) Having the date and time separate makes it easier to distinguish between them. I suspect this is a minor point, however
2) With a QDateTimeEdit, when trying to edit the time, it is possible to select the colon in the time, which then prevents the time from being changed. With a QTimeEdit, this is not possible.

Perhaps there are ways to directly address these concerns other than splitting out the date/time?

> 
> If you want to split it into 2 columns, I would recommend doing this in
> your database with a view (in the database sense, not the model/view
> sense) and a trigger to make the view updatable. If you do this right,
> you can treat the view like a plain old table in QSqlTableModel. There
> is one complication: You will almost certainly have to set the primary
> key in QSqlTableModel yourself since it won't be detected.
> 
> You're halfway there already:
> 
> CREATE VIEW my_view AS
>    SELECT date(timestamp_column) d, time(timestamp_column) t
>    FROM table

I'll have to look into that approach. Even if I don't use it here, it could easily come in handy elsewhere. Thanks!

> 
> -Mark
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100308/1ef0d4c0/attachment.bin 
-------------- next part --------------



More information about the Qt-interest-old mailing list