Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-92112

QDateEdit popup calendar widget adds a comma to the year value when the year has been edited using the calendar widget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 5.15.2
    • 5.15.0
    • None
    • Default en-US locale
    • Linux/X11, macOS, Windows
    • e655f9ce987e44484c94c20f404ca629d60d7686

    Description

      When using a QDateEdit widget with calendarPopup set to true, if the year is changed using the QCalendarWidget (once the popup is activated) adds a comma "," to the year.  It appears that when the title area of the control is updated the year is treated as a 4 digit number that is formatted based on the current locale group seperator.

      Examples:

      Mac 

      Linux

      Windows

      It seems that the following does provide a workaround:

      QDateEdit* dateEdit = new QDateEdit;
      auto calendarWidget = dateEdit->calendarWidget();
      auto locale = calendarWidget->locale();
      locale.setNumberOptions(locale.numberOptions() | QLocale::NumberOption::OmitGroupSeperator);
      calendarWidget->setLocale(locale);

      From the QtDocs for QLocale:

      QLocale::OmitGroupSeparator 0x01 If this option is set, the number-to-string functions will not insert group separators in their return values. The default is to insert group separators.

      It does appear from a quick review of the Qt code that QLocale::toString() is used quite often in QCalendarWidget.

      I was able to reproduce this behavior using the calendar widget example (https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/widgets/calendarwidget?h=5.15) by modifying Window::createDatesGroupBox() and calling the setCalendarPopup(true) for the minimumDateEdit, currentDateEdit, and maximumDateEdit widgets.  Then running the example application, activating one of the 3 calendar popups and changing the year.

      Attachments

        1. image-2021-03-24-16-49-53-768.png
          42 kB
          Nik Twerdochlib
        2. image-2021-03-24-16-51-03-146.png
          23 kB
          Nik Twerdochlib
        3. image-2021-03-24-16-51-43-431.png
          10 kB
          Nik Twerdochlib

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              nikel Nik Twerdochlib
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: