20 lines
703 B
C++
20 lines
703 B
C++
#include "date_time_delegate.h"
|
|
|
|
DateTimeDelegate::DateTimeDelegate(QObject *parent)
|
|
: QStyledItemDelegate(parent) {}
|
|
|
|
QString DateTimeDelegate::displayText(const QVariant &value,
|
|
const QLocale &locale) const {
|
|
QDateTime datetime = QDateTime::fromString(value.toString(), Qt::ISODate);
|
|
if (!datetime.isValid()) {
|
|
return value.toString(); // Return raw value if parsing fails
|
|
}
|
|
|
|
QString formattedDateTime = locale.toString(datetime, QLocale::LongFormat);
|
|
if (!formattedDateTime.isEmpty()) {
|
|
// Capitalize the first letter of the formatted date string
|
|
formattedDateTime[0] = formattedDateTime[0].toUpper();
|
|
}
|
|
return formattedDateTime;
|
|
}
|