问题描述
在 Qt Designer 中,QDateTimeEdit 具有日历视图选项.通过设置显示格式,我只能显示月/年.但是,当用户单击视图时,它会自动显示每日日历.有没有办法让它只显示月/年日历?
In Qt Designer, the QDateTimeEdit has the option for a calendar view. By setting the display format, I am able to only display month/year. However, when the user clicks on the view, it automatically makes a daily calendar show up. Is there a way to make it so only a month/year calendar is displayed?
为了直观的解释,Windows 日历和 Qt 日历有相同的初始视图,但是当我点击年时,它切换到月视图:
To visually explain, the Windows calendar has the same initial view as the Qt calendar, but when I click the year, it switches to a month view:
推荐答案
我建议您使用 QDateEdit
小部件,将其 displayFormat
属性设置为 MM/yyyy
和 currentSection
到 QDateTimeEdit.MonthSection
例如.
I suggest you to use the QDateEdit
widget, setting its displayFormat
attribute to MM/yyyy
and currentSection
to QDateTimeEdit.MonthSection
for instance.
请注意,您可以在编辑值时要求此小部件显示日历 (self.setCalendarPopup(True
)).根据定义,日历将显示日、月和年.
Note that you can ask this widget to display a calendar when editing the value (self.setCalendarPopup(True
)). By definition the calendar will display days, months and years.
这篇关于仅具有年/月视图的 PyQt 日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!