PyQt QDateEdit 选择问题
我有一个 PyQt 应用程序,其中包含 QDateEdit。我对可选择的日期范围设置了限制,该范围是一个月范围内的较短范围,例如28/01/2011 到02/02/2011。
这似乎破坏了 QDateEdit,因为您无法跨月份障碍更改值。假设默认值为 28/01/2011:我们无法将月份增加到 2,因为这会导致日期为 28/02/2011,这是无效的。但是,您无法减少该天,因为这会导致 27/01/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 barrier. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚尝试了一下,情况似乎确实如此。我查看了 C++ 文档,它确实这样说:
QDateTimeEdit 可以配置为允许使用 QCalendarWidget 选择日期。这是通过设置 calendarPopup 属性来启用的。此外,您可以通过调用 setCalendarWidget() 函数提供自定义日历小部件以用作日历弹出窗口。可以使用 calendarWidget() 检索现有的日历小部件。
那么也许你可以用它来设置日期?
编辑:
我能想到的唯一的另一件事是你没有使用 QDateEdit 设置最小值或最大值。然后,您有一个名为“更新日期”的按钮,用于检查最小/最大限制设置的日期。如果不满足这些限制,则会将日期重置为之前的日期。如果它确实满足您使用设定日期的限制。
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.