
Originally Posted by
bala
I am using Qt 4.2.3.
Alright, so you might want to try the approach shown in our wiki. Start with subclassing QSqlTableModel and reimplementing data(). First, you'll get the actual value from base class. Then, you do some adjustments when appropriate, when certain conditions are met:
QVariant MySqlTableModel
::data(const QModelIndex
& index,
int role
) const {
if (!index.isValid())
// get the actual value from base class
// do adjustments if necessary
if (role == Qt::DisplayRole && index.column() == theColumnWhichContainsDates)
{
QDate date
= value.
toDate();
value = date.toString("dd/MM/yyyy");
}
return value;
}
QVariant MySqlTableModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QModelIndex();
// get the actual value from base class
QVariant value = QSqlTableModel::data(index, role);
// do adjustments if necessary
if (role == Qt::DisplayRole && index.column() == theColumnWhichContainsDates)
{
QDate date = value.toDate();
value = date.toString("dd/MM/yyyy");
}
return value;
}
To copy to clipboard, switch view to plain text mode
Bookmarks