From c27348985d528030d2b7d69f1734a26e421172b6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 27 Nov 2017 14:18:24 +0100 Subject: 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 --- src/widgets/itemviews/qabstractitemdelegate.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/widgets') 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); break; - case QVariant::DateTime: { - const QDateTime dateTime = value.toDateTime(); - text = locale.toString(dateTime.date(), formatType) - + QLatin1Char(' ') - + locale.toString(dateTime.time(), formatType); - break; } + case QVariant::DateTime: + text = locale.toString(value.toDateTime(), formatType); + break; default: text = value.toString(); if (role == Qt::DisplayRole) -- cgit v1.2.3