The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date. 更多...
继承 QWidget .
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date.
The widget is initialized with the current month and year, but QCalendarWidget provides several public slots to change the year and month that is shown.
By default, today's date is selected, and the user can select a date using both mouse and keyboard. The currently selected date can be retrieved using the selectedDate () function. It is possible to constrain the user selection to a given date range by setting the minimumDate and maximumDate properties. Alternatively, both properties can be set in one go 使用 setDateRange () convenience slot. Set the selectionMode 特性到 NoSelection to prohibit the user from selecting at all. Note that a date also can be selected programmatically using the setSelectedDate () 槽。
The currently displayed month and year can be retrieved using the monthShown () 和 yearShown () functions, 分别。
A newly created calendar widget uses abbreviated day names, and both Saturdays and Sundays are marked in red. The calendar grid is not visible. The week numbers are displayed, and the first column day is Sunday.
The notation of the days can be altered to a single letter abbreviations ("M" for "Monday") by setting the horizontalHeaderFormat 特性到 QCalendarWidget.SingleLetterDayNames . Setting the same property to QCalendarWidget.LongDayNames makes the header display the complete day names. The week numbers can be removed by setting the verticalHeaderFormat 特性到 QCalendarWidget.NoVerticalHeader . The calendar grid can be turned on by setting the gridVisible 特性到 true using the setGridVisible () 函数:
|
|
QCalendarWidget *calendar; calendar->setGridVisible(true); |
Finally, the day in the first column can be altered using the setFirstDayOfWeek () 函数。
The QCalendarWidget class also provides three signals, selectionChanged (), activated () 和 currentPageChanged () making it possible to respond to user interaction.
The rendering of the headers, weekdays or single days can be largely customized by setting QTextCharFormat 's for some special weekday, a special date or for the rendering of the headers.
Only a subset of the properties in QTextCharFormat are used by the calendar widget. Currently, the foreground, background and font properties are used to determine the rendering of individual cells in the 小部件。
This enum type defines the various formats the horizontal header can display.
| 常量 | 值 | 描述 |
|---|---|---|
| QCalendarWidget.SingleLetterDayNames | 1 | The header displays a single letter abbreviation for day names (e.g. M for Monday). |
| QCalendarWidget.ShortDayNames | 2 | The header displays a short abbreviation for day names (e.g. Mon for Monday). |
| QCalendarWidget.LongDayNames | 3 | The header displays complete day names (e.g. Monday). |
| QCalendarWidget.NoHorizontalHeader | 0 | 头被隐藏。 |
另请参阅 horizontalHeaderFormat () and VerticalHeaderFormat .
This enum describes the types of selection offered to the user for selecting dates in the calendar.
| 常量 | 值 | 描述 |
|---|---|---|
| QCalendarWidget.NoSelection | 0 | Dates cannot be selected. |
| QCalendarWidget.SingleSelection | 1 | Single dates can be selected. |
另请参阅 selectionMode .
This enum type defines the various formats the vertical header can display.
| 常量 | 值 | 描述 |
|---|---|---|
| QCalendarWidget.ISOWeekNumbers | 1 | The header displays ISO week numbers as described by QDate.weekNumber (). |
| QCalendarWidget.NoVerticalHeader | 0 | 头被隐藏。 |
另请参阅 verticalHeaderFormat () and HorizontalHeaderFormat .
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs a calendar widget with the given parent .
The widget is initialized with the current month and year, and the currently selected date is today.
另请参阅 setCurrentPage ().
返回 QMap from QDate to QTextCharFormat showing all dates that use a special format that alters their rendering.
另请参阅 setDateTextFormat ().
返回 QTextCharFormat for date . The char format can be be empty if the date is not renderd specially.
重实现自 QObject.event ().
重实现自 QObject.eventFilter ().
Returns the text char format for rendering the header.
另请参阅 setHeaderTextFormat ().
重实现自 QWidget.keyPressEvent ().
重实现自 QWidget.minimumSizeHint ().
Returns the currently displayed month. Months are numbered from 1 to 12.
另请参阅 yearShown () 和 setCurrentPage ().
重实现自 QWidget.mousePressEvent ().
Paints the cell specified by the given date ,使用 given painter and rect .
重实现自 QWidget.resizeEvent ().
This method is also a Qt slot with the C++ signature void setCurrentPage(int,int) .
Displays the given month of the given year without changing the selected date. Use the setSelectedDate () function to alter the selected date.
The currently displayed month and year can be retrieved using the monthShown () 和 yearShown () functions 分别。
另请参阅 yearShown (), monthShown (), showPreviousMonth (), showNextMonth (), showPreviousYear (),和 showNextYear ().
This method is also a Qt slot with the C++ signature void setDateRange(const QDate&,const QDate&) .
Defines a date range by setting the minimumDate and maximumDate 特性。
The date range restricts the user selection, i.e. the user can only select dates within the specified date range. Note that
QCalendarWidget *calendar; calendar->setDateRange(min, max);
is analogous to
QCalendarWidget *calendar; calendar->setMinimumDate(min); calendar->setMaximumDate(max);
若 min or max parameters are not valid QDate objects, this function does nothing.
另请参阅 setMinimumDate () 和 setMaximumDate ().
Sets the format used to render the given date to that 指定通过 format .
若 date is null, all date formats are cleared.
另请参阅 dateTextFormat ().
Sets the text char format for rendering the header to format . If you also set a weekday text format, this format's foreground and background color will take precedence over the header's format. The other formatting information will still be decided by the header's format.
另请参阅 headerTextFormat ().
This method is also a Qt slot with the C++ signature void setNavigationBarVisible(bool) .
This method is also a Qt slot with the C++ signature void setSelectedDate(const QDate&) .
Sets the text char format for rendering of day in the week dayOfWeek to format . The format will take precedence over the header format in case of foreground and background color. Other text formatting information is taken from the headers format.
另请参阅 weekdayTextFormat () and setHeaderTextFormat ().
This method is also a Qt slot with the C++ signature void showNextMonth() .
Shows the next month relative to the currently displayed month. Note that the selected date is not changed.
另请参阅 showPreviousMonth (), setCurrentPage (), and setSelectedDate ().
This method is also a Qt slot with the C++ signature void showNextYear() .
Shows the currently displayed month in the next year relative to the currently displayed year. Note that the selected date is not changed.
另请参阅 showPreviousYear (), setCurrentPage (), and setSelectedDate ().
This method is also a Qt slot with the C++ signature void showPreviousMonth() .
Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.
另请参阅 showNextMonth (), setCurrentPage (),和 setSelectedDate ().
This method is also a Qt slot with the C++ signature void showPreviousYear() .
Shows the currently displayed month in the 上一 year relative to the currently displayed year. Note that the selected date is not changed.
另请参阅 showNextYear (), setCurrentPage (),和 setSelectedDate ().
This method is also a Qt slot with the C++ signature void showSelectedDate() .
Shows the month of the selected date.
另请参阅 selectedDate () 和 setCurrentPage ().
This method is also a Qt slot with the C++ signature void showToday() .
Shows the month of the today's date.
另请参阅 selectedDate () 和 setCurrentPage ().
重实现自 QWidget.sizeHint ().
Updates the cell specified by the given date unless updates are disabled or the cell is hidden.
该函数在 Qt 4.4 引入。
另请参阅 updateCells (), yearShown (),和 monthShown ().
更新所有可见单元格,除非更新被禁用。
该函数在 Qt 4.4 引入。
另请参阅 updateCell ().
Returns the text char format for rendering of day in the week dayOfWeek .
另请参阅 setWeekdayTextFormat () and headerTextFormat ().
Returns the year of the currently displayed month. Months are numbered from 1 to 12.
另请参阅 monthShown () 和 setCurrentPage ().
This is the default overload of this signal.
This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in the calendar 小部件。
This is the default overload of this signal.
This signal is emitted when a mouse button is clicked. The date the mouse was clicked on is specified by date . The signal is only emitted when clicked on a valid date, e.g., dates are not outside the minimumDate () 和 maximumDate (). If the selection mode is NoSelection , this signal will not be emitted.
This is the default overload of this signal.
This signal is emitted when the currently shown month is changed. The new year and month are passed as 参数。
另请参阅 setCurrentPage ().
This is the default overload of this signal.
This signal is emitted when the currently selected date is 改变。
The currently selected date can be changed by the user using the mouse or keyboard, or by the programmer using setSelectedDate ().
另请参阅 selectedDate ().