diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-09-21 15:58:35 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-10-26 09:43:37 +0200 |
commit | d9edad81177954c89619b6dee70ca76f2f4709ef (patch) | |
tree | 0bf97be29da1290de09f9b447d4105ffb5b0f4c0 | |
parent | ec258b82917e1cbae25854ed38b7f81598644730 (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
Pick-to: 5.15
Change-Id: I092bd1e5f69e544843fd5f28c96b94c9066490c5
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/widgets/widgets/qcalendarwidget.cpp | 2 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 936a6edfe7..6a4abc2113 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -1927,7 +1927,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); @@ -1936,6 +1935,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 ecea005535..ccaf593497 100644 --- a/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp +++ b/tests/auto/widgets/widgets/qcalendarwidget/tst_qcalendarwidget.cpp @@ -185,6 +185,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); |