Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QCalendarWidget Class

TheQCalendarWidget class provides a monthly based calendar widget allowing the user to select a date.More...

Header:#include <QCalendarWidget>
Since: Qt 4.2
Inherits:QWidget

Public Types

enumHorizontalHeaderFormat { SingleLetterDayNames, ShortDayNames, LongDayNames, NoHorizontalHeader }
enumSelectionMode { NoSelection, SingleSelection }
enumVerticalHeaderFormat { ISOWeekNumbers, NoVerticalHeader }

Properties

Public Functions

QCalendarWidget(QWidget * parent = 0)
~QCalendarWidget()
intdateEditAcceptDelay() const
QMap<QDate, QTextCharFormat>dateTextFormat() const
QTextCharFormatdateTextFormat(const QDate & date) const
Qt::DayOfWeekfirstDayOfWeek() const
QTextCharFormatheaderTextFormat() const
HorizontalHeaderFormathorizontalHeaderFormat() const
boolisDateEditEnabled() const
boolisGridVisible() const
boolisNavigationBarVisible() const
QDatemaximumDate() const
QDateminimumDate() const
intmonthShown() const
QDateselectedDate() const
SelectionModeselectionMode() const
voidsetDateEditAcceptDelay(int delay)
voidsetDateEditEnabled(bool enable)
voidsetDateTextFormat(const QDate & date, const QTextCharFormat & format)
voidsetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)
voidsetHeaderTextFormat(const QTextCharFormat & format)
voidsetHorizontalHeaderFormat(HorizontalHeaderFormat format)
voidsetMaximumDate(const QDate & date)
voidsetMinimumDate(const QDate & date)
voidsetSelectionMode(SelectionMode mode)
voidsetVerticalHeaderFormat(VerticalHeaderFormat format)
voidsetWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat & format)
VerticalHeaderFormatverticalHeaderFormat() const
QTextCharFormatweekdayTextFormat(Qt::DayOfWeek dayOfWeek) const
intyearShown() const

Reimplemented Public Functions

virtual QSizeminimumSizeHint() const
virtual QSizesizeHint() const

Public Slots

voidsetCurrentPage(int year, int month)
voidsetDateRange(const QDate & min, const QDate & max)
voidsetGridVisible(bool show)
voidsetNavigationBarVisible(bool visible)
voidsetSelectedDate(const QDate & date)
voidshowNextMonth()
voidshowNextYear()
voidshowPreviousMonth()
voidshowPreviousYear()
voidshowSelectedDate()
voidshowToday()
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidactivated(const QDate & date)
voidclicked(const QDate & date)
voidcurrentPageChanged(int year, int month)
voidselectionChanged()

Protected Functions

virtual voidpaintCell(QPainter * painter, const QRect & rect, const QDate & date) const
voidupdateCell(const QDate & date)
voidupdateCells()

Reimplemented Protected Functions

virtual boolevent(QEvent * event)
virtual booleventFilter(QObject * watched, QEvent * event)
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidmousePressEvent(QMouseEvent * event)
virtual voidresizeEvent(QResizeEvent * event)
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQCalendarWidget class provides a monthly based calendar widget allowing the user to select a date.

The widget is initialized with the current month and year, butQCalendarWidget 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 theselectedDate() function. It is possible to constrain the user selection to a given date range by setting theminimumDate andmaximumDate properties. Alternatively, both properties can be set in one go using thesetDateRange() convenience slot. Set theselectionMode property toNoSelection to prohibit the user from selecting at all. Note that a date also can be selected programmatically using thesetSelectedDate() slot.

The currently displayed month and year can be retrieved using themonthShown() andyearShown() functions, respectively.

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 thehorizontalHeaderFormat property toQCalendarWidget::SingleLetterDayNames. Setting the same property toQCalendarWidget::LongDayNames makes the header display the complete day names. The week numbers can be removed by setting theverticalHeaderFormat property toQCalendarWidget::NoVerticalHeader. The calendar grid can be turned on by setting thegridVisible property to true using thesetGridVisible() function:

QCalendarWidget*calendar;calendar->setGridVisible(true);

Finally, the day in the first column can be altered using thesetFirstDayOfWeek() function.

TheQCalendarWidget class also provides three signals,selectionChanged(),activated() andcurrentPageChanged() making it possible to respond to user interaction.

The rendering of the headers, weekdays or single days can be largely customized by settingQTextCharFormat's for some special weekday, a special date or for the rendering of the headers.

Only a subset of the properties inQTextCharFormat are used by the calendar widget. Currently, the foreground, background and font properties are used to determine the rendering of individual cells in the widget.

See alsoQDate,QDateEdit, andQTextCharFormat.

Member Type Documentation

enum QCalendarWidget::HorizontalHeaderFormat

This enum type defines the various formats the horizontal header can display.

ConstantValueDescription
QCalendarWidget::SingleLetterDayNames1The header displays a single letter abbreviation for day names (e.g. M for Monday).
QCalendarWidget::ShortDayNames2The header displays a short abbreviation for day names (e.g. Mon for Monday).
QCalendarWidget::LongDayNames3The header displays complete day names (e.g. Monday).
QCalendarWidget::NoHorizontalHeader0The header is hidden.

See alsohorizontalHeaderFormat() andVerticalHeaderFormat.

enum QCalendarWidget::SelectionMode

This enum describes the types of selection offered to the user for selecting dates in the calendar.

ConstantValueDescription
QCalendarWidget::NoSelection0Dates cannot be selected.
QCalendarWidget::SingleSelection1Single dates can be selected.

See alsoselectionMode.

enum QCalendarWidget::VerticalHeaderFormat

This enum type defines the various formats the vertical header can display.

ConstantValueDescription
QCalendarWidget::ISOWeekNumbers1The header displays ISO week numbers as described byQDate::weekNumber().
QCalendarWidget::NoVerticalHeader0The header is hidden.

See alsoverticalHeaderFormat() andHorizontalHeaderFormat.

Property Documentation

dateEditAcceptDelay :int

This property holds the time an inactive date edit is shown before its contents are accepted.

If the calendar widget'sdate edit is enabled, this property specifies the amount of time (in millseconds) that the date edit remains open after the most recent user input. Once this time has elapsed, the date specified in the date edit is accepted and the popup is closed.

By default, the delay is defined to be 1500 milliseconds (1.5 seconds).

This property was introduced in Qt 4.3.

Access functions:

intdateEditAcceptDelay() const
voidsetDateEditAcceptDelay(int delay)

dateEditEnabled :bool

This property holds whether the date edit popup is enabled.

If this property is enabled, pressing a non-modifier key will cause a date edit to popup if the calendar widget has focus, allowing the user to specify a date in the form specified by the current locale.

By default, this property is enabled.

The date edit is simpler in appearance thanQDateEdit, but allows the user to navigate between fields using the left and right cursor keys, increment and decrement individual fields using the up and down cursor keys, and enter values directly using the number keys.

This property was introduced in Qt 4.3.

Access functions:

boolisDateEditEnabled() const
voidsetDateEditEnabled(bool enable)

See alsoQCalendarWidget::dateEditAcceptDelay.

firstDayOfWeek :Qt::DayOfWeek

This property holds a value identifying the day displayed in the first column.

By default, the day displayed in the first column is Sunday

Access functions:

Qt::DayOfWeekfirstDayOfWeek() const
voidsetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)

gridVisible :bool

This property holds whether the table grid is displayed.

QCalendarWidget*calendar;calendar->setGridVisible(true);

The default value is false.

Access functions:

boolisGridVisible() const
voidsetGridVisible(bool show)

horizontalHeaderFormat :HorizontalHeaderFormat

This property holds the format of the horizontal header.

The default value isQCalendarWidget::ShortDayNames.

Access functions:

HorizontalHeaderFormathorizontalHeaderFormat() const
voidsetHorizontalHeaderFormat(HorizontalHeaderFormat format)

maximumDate :QDate

This property holds the maximum date of the currently specified date range.

The user will not be able to select a date which is after the currently set maximum date.

QCalendarWidget*calendar;calendar->setGridVisible(true);calendar->setMaximumDate(QDate(2006,7,3));

By default, the maximum date is the last day theQDate class can handle.

When setting a maximum date, theminimumDate andselectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate object, the setMaximumDate() function does nothing.

Access functions:

QDatemaximumDate() const
voidsetMaximumDate(const QDate & date)

See alsosetDateRange().

minimumDate :QDate

This property holds the minimum date of the currently specified date range.

The user will not be able to select a date that is before the currently set minimum date.

QCalendarWidget*calendar;calendar->setGridVisible(true);calendar->setMinimumDate(QDate(2006,6,19));

By default, the minimum date is the earliest date that theQDate class can handle.

When setting a minimum date, themaximumDate andselectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a validQDate object, the setMinimumDate() function does nothing.

Access functions:

QDateminimumDate() const
voidsetMinimumDate(const QDate & date)

See alsosetDateRange().

navigationBarVisible :bool

This property holds whether the navigation bar is shown or not.

When this property is true (the default), the next month, previous month, month selection, year selection controls are shown on top.

When the property is set to false, these controls are hidden.

This property was introduced in Qt 4.3.

Access functions:

boolisNavigationBarVisible() const
voidsetNavigationBarVisible(bool visible)

selectedDate :QDate

This property holds the currently selected date.

The selected date must be within the date range specified by theminimumDate andmaximumDate properties. By default, the selected date is the current date.

Access functions:

QDateselectedDate() const
voidsetSelectedDate(const QDate & date)

See alsosetDateRange().

selectionMode :SelectionMode

This property holds the type of selection the user can make in the calendar.

When this property is set toSingleSelection, the user can select a date within the minimum and maximum allowed dates, using either the mouse or the keyboard.

When the property is set toNoSelection, the user will be unable to select dates, but they can still be selected programmatically. Note that the date that is selected when the property is set toNoSelection will still be the selected date of the calendar.

The default value isSingleSelection.

Access functions:

SelectionModeselectionMode() const
voidsetSelectionMode(SelectionMode mode)

verticalHeaderFormat :VerticalHeaderFormat

This property holds the format of the vertical header.

The default value is QCalendarWidget::ISOWeekNumber.

Access functions:

VerticalHeaderFormatverticalHeaderFormat() const
voidsetVerticalHeaderFormat(VerticalHeaderFormat format)

Member Function Documentation

QCalendarWidget::QCalendarWidget(QWidget * parent = 0)

Constructs a calendar widget with the givenparent.

The widget is initialized with the current month and year, and the currently selected date is today.

See alsosetCurrentPage().

QCalendarWidget::~QCalendarWidget()

Destroys the calendar widget.

[signal]void QCalendarWidget::activated(constQDate & date)

This signal is emitted whenever the user presses the Return or Enter key or double-clicks adate in the calendar widget.

[signal]void QCalendarWidget::clicked(constQDate & date)

This signal is emitted when a mouse button is clicked. The date the mouse was clicked on is specified bydate. The signal is only emitted when clicked on a valid date, e.g., dates are not outside theminimumDate() andmaximumDate(). If the selection mode isNoSelection, this signal will not be emitted.

[signal]void QCalendarWidget::currentPageChanged(int year,int month)

This signal is emitted when the currently shown month is changed. The newyear andmonth are passed as parameters.

See alsosetCurrentPage().

QMap<QDate,QTextCharFormat> QCalendarWidget::dateTextFormat() const

Returns aQMap fromQDate toQTextCharFormat showing all dates that use a special format that alters their rendering.

See alsosetDateTextFormat().

QTextCharFormat QCalendarWidget::dateTextFormat(constQDate & date) const

Returns aQTextCharFormat fordate. The char format can be be empty if the date is not renderd specially.

[virtual protected]bool QCalendarWidget::event(QEvent * event)

Reimplemented fromQObject::event().

[virtual protected]bool QCalendarWidget::eventFilter(QObject * watched,QEvent * event)

Reimplemented fromQObject::eventFilter().

QTextCharFormat QCalendarWidget::headerTextFormat() const

Returns the text char format for rendering the header.

See alsosetHeaderTextFormat().

[virtual protected]void QCalendarWidget::keyPressEvent(QKeyEvent * event)

Reimplemented fromQWidget::keyPressEvent().

[virtual]QSize QCalendarWidget::minimumSizeHint() const

Reimplemented fromQWidget::minimumSizeHint().

int QCalendarWidget::monthShown() const

Returns the currently displayed month. Months are numbered from 1 to 12.

See alsoyearShown() andsetCurrentPage().

[virtual protected]void QCalendarWidget::mousePressEvent(QMouseEvent * event)

Reimplemented fromQWidget::mousePressEvent().

[virtual protected]void QCalendarWidget::paintCell(QPainter * painter, constQRect & rect, constQDate & date) const

Paints the cell specified by the givendate, using the givenpainter andrect.

[virtual protected]void QCalendarWidget::resizeEvent(QResizeEvent * event)

Reimplemented fromQWidget::resizeEvent().

[signal]void QCalendarWidget::selectionChanged()

This signal is emitted when the currently selected date is changed.

The currently selected date can be changed by the user using the mouse or keyboard, or by the programmer usingsetSelectedDate().

See alsoselectedDate().

[slot]void QCalendarWidget::setCurrentPage(int year,int month)

Displays the givenmonth of the givenyear without changing the selected date. Use thesetSelectedDate() function to alter the selected date.

The currently displayed month and year can be retrieved using themonthShown() andyearShown() functions respectively.

See alsoyearShown(),monthShown(),showPreviousMonth(),showNextMonth(),showPreviousYear(), andshowNextYear().

[slot]void QCalendarWidget::setDateRange(constQDate & min, constQDate & max)

Defines a date range by setting theminimumDate andmaximumDate properties.

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);

If either themin ormax parameters are not validQDate objects, this function does nothing.

See alsosetMinimumDate() andsetMaximumDate().

void QCalendarWidget::setDateTextFormat(constQDate & date, constQTextCharFormat & format)

Sets the format used to render the givendate to that specified byformat.

Ifdate is null, all date formats are cleared.

See alsodateTextFormat().

void QCalendarWidget::setHeaderTextFormat(constQTextCharFormat & format)

Sets the text char format for rendering the header toformat. 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.

See alsoheaderTextFormat().

void QCalendarWidget::setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, constQTextCharFormat & format)

Sets the text char format for rendering of day in the weekdayOfWeek toformat. 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.

See alsoweekdayTextFormat() andsetHeaderTextFormat().

[slot]void QCalendarWidget::showNextMonth()

Shows the next month relative to the currently displayed month. Note that the selected date is not changed.

See alsoshowPreviousMonth(),setCurrentPage(), andsetSelectedDate().

[slot]void QCalendarWidget::showNextYear()

Shows the currently displayed month in thenext year relative to the currently displayed year. Note that the selected date is not changed.

See alsoshowPreviousYear(),setCurrentPage(), andsetSelectedDate().

[slot]void QCalendarWidget::showPreviousMonth()

Shows the previous month relative to the currently displayed month. Note that the selected date is not changed.

See alsoshowNextMonth(),setCurrentPage(), andsetSelectedDate().

[slot]void QCalendarWidget::showPreviousYear()

Shows the currently displayed month in theprevious year relative to the currently displayed year. Note that the selected date is not changed.

See alsoshowNextYear(),setCurrentPage(), andsetSelectedDate().

[slot]void QCalendarWidget::showSelectedDate()

Shows the month of the selected date.

See alsoselectedDate() andsetCurrentPage().

[slot]void QCalendarWidget::showToday()

Shows the month of the today's date.

See alsoselectedDate() andsetCurrentPage().

[virtual]QSize QCalendarWidget::sizeHint() const

Reimplemented fromQWidget::sizeHint().

[protected]void QCalendarWidget::updateCell(constQDate & date)

Updates the cell specified by the givendate unless updates are disabled or the cell is hidden.

This function was introduced in Qt 4.4.

See alsoupdateCells(),yearShown(), andmonthShown().

[protected]void QCalendarWidget::updateCells()

Updates all visible cells unless updates are disabled.

This function was introduced in Qt 4.4.

See alsoupdateCell().

QTextCharFormat QCalendarWidget::weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const

Returns the text char format for rendering of day in the weekdayOfWeek.

See alsosetWeekdayTextFormat() andheaderTextFormat().

int QCalendarWidget::yearShown() const

Returns the year of the currently displayed month. Months are numbered from 1 to 12.

See alsomonthShown() andsetCurrentPage().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp