path: root/src
diff options
authorEdward Welbourne <>2017-11-27 14:18:24 +0100
committerEdward Welbourne <>2017-11-30 20:21:42 +0000
commitc27348985d528030d2b7d69f1734a26e421172b6 (patch)
tree3e9aa9e25205637b3457c80103c4ddf5106c0d14 /src
parent454bbbe787003be8ba41999ad5e3237b02deafd7 (diff)
Simplify date-time formatting in textForRole()
QAbstractItemDelegatePrivate::textForRole() was formatting date and time separately, then gluing the parts back together with space. QLocale can do that just fine itself (it has a toString() overload that handles a QDateTime) and might even (some day) do it better. To my mild surprise, this proved sufficient to fix a problem with date-time display in tool-tips, when the date-time includes a zone. Extracted the date-time part of an existing selftest into a test of its own and extended it to test times of each spec-type; verified that the non-local spec cases of this all failed before this fix. Task-number: QTBUG-61069 Change-Id: I6d6be0c27be9a557d8afc3ced200a10b2aaff816 Reviewed-by: Marc Mutz <>
Diffstat (limited to 'src')
1 files changed, 3 insertions, 6 deletions
diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp
index d532221092..6cb7c8600d 100644
--- a/src/widgets/itemviews/qabstractitemdelegate.cpp
+++ b/src/widgets/itemviews/qabstractitemdelegate.cpp
@@ -585,12 +585,9 @@ QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const Q
case QVariant::Time:
text = locale.toString(value.toTime(), formatType);
- case QVariant::DateTime: {
- const QDateTime dateTime = value.toDateTime();
- text = locale.toString(, formatType)
- + QLatin1Char(' ')
- + locale.toString(dateTime.time(), formatType);
- break; }
+ case QVariant::DateTime:
+ text = locale.toString(value.toDateTime(), formatType);
+ break;
text = value.toString();
if (role == Qt::DisplayRole)