summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-09-21 15:58:35 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-26 11:41:50 +0000
commite655f9ce987e44484c94c20f404ca629d60d7686 (patch)
tree7efad3ca4ef3c156ea3be4f21b1e1800d12880f3
parent1f2c756f8e493fff3c4708399149fa3c79dd9fad (diff)
Show the year correctly after it has been edited
When converting the year as an integer via the locale then it can add in group separators which would not be desired here. Therefore it should be converted via the QDate approach to get the right output for the year. Fixes: QTBUG-86307 Fixes: QTBUG-85966 Change-Id: I092bd1e5f69e544843fd5f28c96b94c9066490c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit d9edad81177954c89619b6dee70ca76f2f4709ef) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp2
-rw-r--r--tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp4
2 files changed, 5 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index f9345d056c..bb64edd85d 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -1928,7 +1928,6 @@ void QCalendarWidgetPrivate::_q_nextMonthClicked()
void QCalendarWidgetPrivate::_q_yearEditingFinished()
{
Q_Q(QCalendarWidget);
- yearButton->setText(q->locale().toString(yearEdit->value()));
yearEdit->hide();
q->setFocusPolicy(oldFocusPolicy);
qApp->removeEventFilter(q);
@@ -1937,6 +1936,7 @@ void QCalendarWidgetPrivate::_q_yearEditingFinished()
QDate currentDate = getCurrentDate();
int newYear = q->locale().toInt(yearEdit->text());
currentDate = currentDate.addYears(newYear - currentDate.year(m_model->m_calendar), m_model->m_calendar);
+ yearButton->setText(q->locale().toString(currentDate, u"yyyy", m_model->m_calendar));
updateCurrentPage(currentDate);
}
diff --git a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp
index c3ae2ea541..2d74e71302 100644
--- a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp
+++ b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp
@@ -188,6 +188,10 @@ void tst_QCalendarWidget::buttonClickCheck()
QTest::mouseMove(widget);
QTest::mouseClick(widget, Qt::LeftButton);
QCOMPARE(2006, object.yearShown());
+ QTest::mouseClick(button, Qt::LeftButton, Qt::NoModifier, button->rect().center(), 2);
+ QTest::mouseMove(widget);
+ QTest::mouseClick(widget, Qt::LeftButton);
+ QCOMPARE(button->text(), "2006"); // Check that it is shown as a year should be
object.setSelectedDate(selectedDate);
object.showSelectedDate();
QTest::keyClick(widget, Qt::Key_Down);