开发者

PyQt QDateEdit Selection Issues

开发者 https://www.devze.com 2023-04-12 19:53 出处:网络
I have a PyQt application, which contains a QDateEdit. I\'ve set a limit to the date range which can be selected, which is a short range over the boundary of a month, e.g. 28/01/2011 to 02/02/2011.

I have a PyQt application, which contains a QDateEdit. I've set a limit to the date range which can be selected, which is a short range over the boundary of a month, e.g. 28/01/2011 to 02/02/2011.

This seems to break the QDateEdit, because you cannot change the values across the month bar开发者_运维知识库rier. Say the default is 28/01/2011: we can't increase the month to 2, because this would result in the date of 28/02/2011, which isn't valid. However, you can't decrease the day, because this would result in 27/01/2011, which isn't valid.

Is this a bug, or does anyone know a way around it?


I just tried this out and it does seem to be the case. I looked at the C++ documentation and it does say this:

QDateTimeEdit can be configured to allow a QCalendarWidget to be used to select dates. This is enabled by setting the calendarPopup property. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling the setCalendarWidget() function. The existing calendar widget can be retrieved with calendarWidget().

So maybe you can use that to set the date?

Edit:

The only other thing I can think of is you don't set a min or max with QDateEdit. Then you have a button called "Update Date" that checks the date set for the min/max restrictions. If it doesn't meet those restrictions, it resets the date to what it was previously. If it does meet the restrictions you use the date set.

0

精彩评论

暂无评论...
验证码 换一张
取 消