PDA

View Full Version : QTableView & QDate



Shaitan
18th July 2007, 10:03
Hi,
I have a DB table with a date column on it, it has a short date format (dd/MM/yyyy). I use a QSqlTableModel to hold this table's data, and its connected to a QTableView. The problem is that when i display it, the data has a QDateTime format (dd/MM/yyyy 0:00:00). Although the date format is correct, i dont want the time to be displayed (its not recorded in the DB). I guess this is because a conversion between QVariant and the QString in the model...

Any idea?

Thx!

Michiel
18th July 2007, 10:13
Reimplement the data() function of the model. If you want the table-view to display a date editor / date display, make sure you return a QDate.

If you really want only a string there, you simply have to extract a QDate from the QVariant and use the correct format in the function QDate::toString().

Shaitan
18th July 2007, 10:31
if i reimplement QSqlTableModel::Data() i will also have to take the updates of the table into account, is that correct? the table is editable, so this can be a bit difficult... :confused:
Is there any other easier way?

J.

Michiel
18th July 2007, 11:06
For handling edits and updates on the table, reimplement setData(). That's how the model/view classes were designed to work together.