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

QDateEdit: setting min/max may make some dates inaccessible

    XMLWordPrintable

Details

    Description

      QDateEdit does not allow typing or scrolling through dates outside (min,max). This makes some dates inaccessible neither by typing nor by scrolling the spin-arrows if multiple sections have to be changed to get to a proper date.

      Example:

      #include <QApplication>
      #include <QDateEdit>
      
      int main( int argc, char * argv[] )
      {
      	QApplication a( argc, argv );
      
      	QDateEdit * _dateedit = new QDateEdit();
      	_dateedit->setDisplayFormat("dd-MM-yyyy");
      	_dateedit->setMinimumDate(QDate(2010, 12, 20));
      	_dateedit->setMaximumDate(QDate(2011, 1, 10));
      	_dateedit->show();
      
      	return a.exec();
      }
      

      QDateEdit with min 20 Dec 2010, max 10 Jan 2011. We start with "20 Dec 2010" and ... how can we get to Jan 2011? You cannot change day to less than 20 if month/year is Dec 2010 (this would lead for a moment to e.g. 3 Dec 2010 which is not allowed)... You cannot scroll year up to 2011 (because this would lead for a moment to e.g. 20 Dec 2011 which is not allowed). Basically a user is stuck with dates between 20 and 31 Dec 2010...

      Another example: imagine you allow in a QDateWidget dates from today till today + 10 days. If today is 29-Jan-2011, then formally max of the widget is 7-Feb-2011, but ... user will never be able to choose a date from February, he/she can only choose between 29, 30 and 31 of January.

      Note that this is a problem from our (programmers') point of view. If we really want to enable the 10 days in the last example, we cannot use (min,max). We have to allow now large range of dates and then upon change of the date in dateedit check in our code if it is within (min, max) and e.g. enable "accept" button based on this, indicate to the user that the problem is with the value of this particular widget etc... Quite a bit of extra work (+it is weird to allow the user to type a "wrong" date and then to complain about this...)

      ================
      Possible simple solution:

      Right now, if you have max day in the selected month (e.g.. 31 in the case of Dec) you cannot scroll up. I think the simplest (and relatively clear in ui) solution would be to say that you can scroll up from "31" and this would simply step over to the next month.
      '31-12-2010' => scroll up by one day => '1-1-2011'.
      Note that if it works also the other way around (you can scroll down one day from 1-1-2011 and you will get 31-12-2010) then it would not be inconvenient for users to scroll a bit too much by mistake. Note also that since right now scrolling up from the max day is blocked, such functionality would not replace something for which users have already some intuition => it would be something extra which has just benefits basically without side effects!

      I would suggest that scrolling up the month or year should still be not allowed if preserving day would lead to a date outside of (min, max) (users may be used to setting day first, then scrolling to [or typing in] proper month and year -> it might be weird if scrolling month would sometimes adjust the day).

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              vhilshei Volker Hilsheimer
              wiecko Marek Wieckowski
              Votes:
              5 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes