QCalendarWidget Class Reference

#include <qcalendarwidget.h>

Inheritance diagram for QCalendarWidget:

Inheritance graph
[legend]
Collaboration diagram for QCalendarWidget:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

Since:
4.2
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. The currently displayed month and year can be retrieved using the currentPageMonth() and currentPageYear() functions, respectively.

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 using the setDateRange() convenience slot. Set the selectionMode property to NoSelection to prohibit the user from selecting at all. Note that a date also can be selected programmatically using the setSelectedDate() slot.

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 property to 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 property to QCalendarWidget::NoVerticalHeader. The calendar grid can be turned on by setting the gridVisible property to true using the setGridVisible() function:

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

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

The QCalendarWidget class also provides three signals, selectionChanged(), activated() and 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 widget.

See also:
QDate, QDateEdit, QTextCharFormat

Definition at line 40 of file qcalendarwidget.h.

Public Types

enum  HorizontalHeaderFormat
enum  VerticalHeaderFormat
enum  SelectionMode

Public Slots

void setSelectedDate (const QDate &date)
void setDateRange (const QDate &min, const QDate &max)
void setCurrentPage (int year, int month)
void showNextMonth ()
void showPreviousMonth ()
void showNextYear ()
void showPreviousYear ()
void showSelectedDate ()
void showToday ()

Signals

void selectionChanged ()
void clicked (const QDate &date)
void activated (const QDate &date)
void currentPageChanged (int year, int month)

Public Member Functions

 QCalendarWidget (QWidget *parent=0)
 ~QCalendarWidget ()
virtual QSize sizeHint () const
virtual QSize minimumSizeHint () const
QDate selectedDate () const
int yearShown () const
int monthShown () const
QDate minimumDate () const
void setMinimumDate (const QDate &date)
QDate maximumDate () const
void setMaximumDate (const QDate &date)
Qt::DayOfWeek firstDayOfWeek () const
void setFirstDayOfWeek (Qt::DayOfWeek dayOfWeek)
bool isHeaderVisible () const
void setHeaderVisible (bool show)
bool isGridVisible () const
void setGridVisible (bool show)
SelectionMode selectionMode () const
void setSelectionMode (SelectionMode mode)
HorizontalHeaderFormat horizontalHeaderFormat () const
void setHorizontalHeaderFormat (HorizontalHeaderFormat format)
VerticalHeaderFormat verticalHeaderFormat () const
void setVerticalHeaderFormat (VerticalHeaderFormat format)
QTextCharFormat headerTextFormat () const
void setHeaderTextFormat (const QTextCharFormat &format)
QTextCharFormat weekdayTextFormat (Qt::DayOfWeek dayOfWeek) const
void setWeekdayTextFormat (Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format)
QMap< QDate, QTextCharFormatdateTextFormat () const
QTextCharFormat dateTextFormat (const QDate &date) const
void setDateTextFormat (const QDate &date, const QTextCharFormat &color)

Protected Member Functions

bool event (QEvent *event)
void mousePressEvent (QMouseEvent *event)
void resizeEvent (QResizeEvent *event)
void keyPressEvent (QKeyEvent *event)
virtual void paintCell (QPainter *painter, const QRect &rect, const QDate &date) const

Private Member Functions

 Q_PRIVATE_SLOT (d_func(), void _q_slotChangeDate(const QDate &date, bool changeMonth)) Q_PRIVATE_SLOT(d_func()
void _q_editingFinished ()) Q_PRIVATE_SLOT(d_func()
void void _q_prevMonthClicked ()) Q_PRIVATE_SLOT(d_func()
void void void _q_nextMonthClicked ()) Q_PRIVATE_SLOT(d_func()
void void void void _q_yearEditingFinished ()) Q_PRIVATE_SLOT(d_func()
void void void void void _q_yearClicked ()) Q_PRIVATE_SLOT(d_func()


Member Enumeration Documentation

enum QCalendarWidget::HorizontalHeaderFormat

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

SingleLetterDayNames The header displays a single letter abbreviation for day names (e.g. M for Monday). ShortDayNames The header displays a short abbreviation for day names (e.g. Mon for Monday). LongDayNames The header displays complete day names (e.g. Monday). NoHorizontalHeader The header is hidden.

See also:
horizontalHeaderFormat(), VerticalHeaderFormat

Definition at line 58 of file qcalendarwidget.h.

00058                                 {
00059         NoHorizontalHeader,
00060         SingleLetterDayNames,
00061         ShortDayNames,
00062         LongDayNames
00063     };

enum QCalendarWidget::VerticalHeaderFormat

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

ISOWeekNumbers The header displays a ISO week numbers QDate::weekNumber(). NoVerticalHeader The header is hidden.

See also:
verticalHeaderFormat(), HorizontalHeaderFormat

Definition at line 65 of file qcalendarwidget.h.

00065                               {
00066         NoVerticalHeader,
00067         ISOWeekNumbers
00068     };

enum QCalendarWidget::SelectionMode

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

NoSelection Dates cannot be selected. SingleSelection Single dates can be selected.

See also:
selectionMode

Definition at line 70 of file qcalendarwidget.h.

00070                        {
00071         NoSelection,
00072         SingleSelection
00073     };


Constructor & Destructor Documentation

QCalendarWidget::QCalendarWidget ( QWidget parent = 0  )  [explicit]

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.

See also:
setCurrentPage()

Definition at line 1163 of file qcalendarwidget.cpp.

References _q_editingFinished(), _q_nextMonthClicked(), _q_prevMonthClicked(), _q_yearClicked(), _q_yearEditingFinished(), QBoxLayout::addWidget(), clicked(), QObject::connect(), d, QFrame::NoFrame, QSizePolicy::Preferred, Qt::red, Qt::Saturday, QAbstractItemView::SelectItems, QWidget::setAutoFillBackground(), QWidget::setBackgroundRole(), QWidget::setFocusPolicy(), QWidget::setFocusProxy(), QTextFormat::setForeground(), QLayout::setMargin(), QWidget::setSizePolicy(), QLayout::setSpacing(), SIGNAL, QAbstractItemView::SingleSelection, SLOT, QHeaderView::Stretch, Qt::StrongFocus, Qt::Sunday, and QPalette::Window.

01164     : QWidget(*new QCalendarWidgetPrivate, parent, 0)
01165 {
01166     Q_D(QCalendarWidget);
01167 
01168     setAutoFillBackground(true);
01169     setBackgroundRole(QPalette::Window);
01170 
01171     QVBoxLayout *layoutV = new QVBoxLayout(this);
01172     layoutV->setMargin(0);
01173     d->m_model = new QCalendarModel(this);
01174     QTextCharFormat fmt;
01175     fmt.setForeground(QBrush(Qt::red));
01176     d->m_model->m_dayFormats.insert(Qt::Saturday, fmt);
01177     d->m_model->m_dayFormats.insert(Qt::Sunday, fmt);
01178     d->m_view = new QCalendarView(this);
01179     d->m_view->setObjectName("qt_calendar_calendarview");
01180     d->m_view->setModel(d->m_model);
01181     d->m_model->setView(d->m_view);
01182     d->m_view->setSelectionBehavior(QAbstractItemView::SelectItems);
01183     d->m_view->setSelectionMode(QAbstractItemView::SingleSelection);
01184     d->m_view->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
01185     d->m_view->horizontalHeader()->setClickable(false);
01186     d->m_view->verticalHeader()->setResizeMode(QHeaderView::Stretch);
01187     d->m_view->verticalHeader()->setClickable(false);
01188     d->m_selection = d->m_view->selectionModel();
01189     d->createHeader(this);
01190     d->m_view->setFrameStyle(QFrame::NoFrame);
01191     d->m_delegate = new QCalendarDelegate(d, this);
01192     d->m_view->setItemDelegate(d->m_delegate);
01193     d->update();
01194     d->updateHeader();
01195     setFocusPolicy(Qt::StrongFocus);
01196     setFocusProxy(d->m_view);
01197     setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
01198 
01199     connect(d->m_view, SIGNAL(changeDate(QDate,bool)),
01200             this, SLOT(_q_slotChangeDate(QDate,bool)));
01201     connect(d->m_view, SIGNAL(clicked(QDate)),
01202             this, SIGNAL(clicked(QDate)));
01203     connect(d->m_view, SIGNAL(editingFinished()),
01204             this, SLOT(_q_editingFinished()));
01205 
01206     connect(d->prevMonth, SIGNAL(clicked(bool)),
01207             this, SLOT(_q_prevMonthClicked()));
01208     connect(d->nextMonth, SIGNAL(clicked(bool)),
01209             this, SLOT(_q_nextMonthClicked()));
01210     connect(d->yearButton, SIGNAL(clicked(bool)),
01211             this, SLOT(_q_yearClicked()));
01212     connect(d->monthMenu, SIGNAL(triggered(QAction*)),
01213             this, SLOT(_q_monthChanged(QAction*)));
01214     connect(d->yearEdit, SIGNAL(editingFinished()),
01215             this, SLOT(_q_yearEditingFinished()));
01216 
01217     layoutV->setMargin(0);
01218     layoutV->setSpacing(0);
01219     layoutV->addWidget(d->headerBackground);
01220     layoutV->addWidget(d->m_view);
01221 }

Here is the call graph for this function:

QCalendarWidget::~QCalendarWidget (  ) 

Destroys the calendar widget.

Definition at line 1226 of file qcalendarwidget.cpp.

01227 {
01228 }


Member Function Documentation

QSize QCalendarWidget::sizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 1233 of file qcalendarwidget.cpp.

References minimumSizeHint().

01234 {
01235     return minimumSizeHint();
01236 }

Here is the call graph for this function:

QSize QCalendarWidget::minimumSizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 1241 of file qcalendarwidget.cpp.

References QFontMetrics::boundingRect(), d, QWidget::ensurePolished(), h, horizontalHeaderFormat(), i, QDate::longMonthName(), NoHorizontalHeader, NoVerticalHeader, QString::number(), QStyle::pixelMetric(), QStyle::PM_FocusFrameHMargin, qMax(), QWidget::style(), verticalHeaderFormat(), w, and QRect::width().

Referenced by sizeHint().

01242 {
01243     Q_D(const QCalendarWidget);
01244 
01245     ensurePolished();
01246 
01247     int w = 0;
01248     int h = 0;
01249 
01250     int end = 53;
01251     int rows = 7;
01252     int cols = 8;
01253     int startRow = 0;
01254     int startCol = 0;
01255 
01256     const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2;
01257 
01258     if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) {
01259         rows = 6;
01260         startRow = 1;
01261     } else {
01262         for (int i = 1; i <= 7; i++) {
01263             QFontMetrics fm(d->m_model->formatForCell(0, i).font());
01264             w = qMax(w, fm.width(d->m_model->dayName(i)) + marginH);
01265             h = qMax(h, fm.height());
01266         }
01267     }
01268 
01269     if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) {
01270         cols = 7;
01271         startCol = 1;
01272     }
01273 
01274     QFontMetrics fm(d->m_model->formatForCell(1, 1).font());
01275     for (int i = 1; i <= end; i++) {
01276         w = qMax(w, fm.width(QString::number(i)) + marginH);
01277         h = qMax(h, fm.height());
01278     }
01279 
01280     if (d->m_view->showGrid()) {
01281         // hardcoded in tableview
01282         w += 1;
01283         h += 1;
01284     }
01285 
01286     w += 1; // default column span
01287 
01288     h = qMax(h, d->m_view->verticalHeader()->minimumSectionSize());
01289     w = qMax(w, d->m_view->horizontalHeader()->minimumSectionSize());
01290 
01291     //add the size of the header.
01292     QSize headerSize(0, 0);
01293     if (d->headerVisible) {
01294         int headerH = d->headerBackground->sizeHint().height();
01295         int headerW = 0;
01296 
01297         headerW += d->prevMonth->sizeHint().width();
01298         headerW += d->nextMonth->sizeHint().width();
01299 
01300         QFontMetrics fm = d->monthButton->fontMetrics();
01301         int monthW = 0;
01302         for (int i = 1; i < 12; i++)
01303             monthW = qMax(monthW, fm.boundingRect(QDate::longMonthName(i)).width());
01304         monthW += fm.boundingRect(QChar('y')).width();
01305         headerW += monthW;
01306 
01307         fm = d->yearButton->fontMetrics();
01308         headerW += fm.boundingRect(QString("55555")).width();
01309 
01310         headerSize = QSize(headerW, headerH);
01311     }
01312     w *= cols;
01313     w = qMax(headerSize.width(), w);
01314     h = (h * rows) + headerSize.height();
01315     return QSize(w , h);
01316 }

Here is the call graph for this function:

QDate QCalendarWidget::selectedDate (  )  const

Definition at line 1339 of file qcalendarwidget.cpp.

References d.

Referenced by QCalendarPopup::dateSelectionChanged(), QCalendarPopup::selectedDate(), and showSelectedDate().

01340 {
01341     Q_D(const QCalendarWidget);
01342     return d->m_model->date;
01343 }

int QCalendarWidget::yearShown (  )  const

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

See also:
monthShown(), setCurrentPage()

Definition at line 1367 of file qcalendarwidget.cpp.

References d.

Referenced by keyPressEvent(), showNextMonth(), showNextYear(), showPreviousMonth(), and showPreviousYear().

01368 {
01369     Q_D(const QCalendarWidget);
01370     return d->m_model->shownYear;
01371 }

int QCalendarWidget::monthShown (  )  const

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

See also:
yearShown(), setCurrentPage()

Definition at line 1380 of file qcalendarwidget.cpp.

References d.

Referenced by showNextMonth(), showNextYear(), showPreviousMonth(), and showPreviousYear().

01381 {
01382     Q_D(const QCalendarWidget);
01383     return d->m_model->shownMonth;
01384 }

QDate QCalendarWidget::minimumDate (  )  const

Definition at line 1528 of file qcalendarwidget.cpp.

References d.

01529 {
01530     Q_D(const QCalendarWidget);
01531     return d->m_model->minimumDate;
01532 }

void QCalendarWidget::setMinimumDate ( const QDate date  ) 

Definition at line 1534 of file qcalendarwidget.cpp.

References d, emit, QDate::isValid(), QDate::month(), selectionChanged(), and QDate::year().

Referenced by QCalendarPopup::setDateRange().

01535 {
01536     Q_D(QCalendarWidget);
01537     if (!date.isValid() || d->m_model->minimumDate == date)
01538         return;
01539 
01540     QDate oldDate = d->m_model->date;
01541     d->m_model->setMinimumDate(date);
01542     d->yearEdit->setMinimum(d->m_model->minimumDate.year());
01543     d->updateMonthMenu();
01544     QDate newDate = d->m_model->date;
01545     if (oldDate != newDate) {
01546         d->update();
01547         d->showMonth(newDate.year(), newDate.month());
01548         emit selectionChanged();
01549     }
01550 }

Here is the call graph for this function:

QDate QCalendarWidget::maximumDate (  )  const

Definition at line 1582 of file qcalendarwidget.cpp.

References d.

01583 {
01584     Q_D(const QCalendarWidget);
01585     return d->m_model->maximumDate;
01586 }

void QCalendarWidget::setMaximumDate ( const QDate date  ) 

Definition at line 1588 of file qcalendarwidget.cpp.

References d, emit, QDate::isValid(), QDate::month(), selectionChanged(), and QDate::year().

Referenced by QCalendarPopup::setDateRange().

01589 {
01590     Q_D(QCalendarWidget);
01591     if (!date.isValid() || d->m_model->maximumDate == date)
01592         return;
01593 
01594     QDate oldDate = d->m_model->date;
01595     d->m_model->setMaximumDate(date);
01596     d->yearEdit->setMaximum(d->m_model->maximumDate.year());
01597     d->updateMonthMenu();
01598     QDate newDate = d->m_model->date;
01599     if (oldDate != newDate) {
01600         d->update();
01601         d->showMonth(newDate.year(), newDate.month());
01602         emit selectionChanged();
01603     }
01604 }

Here is the call graph for this function:

Qt::DayOfWeek QCalendarWidget::firstDayOfWeek (  )  const

Definition at line 1816 of file qcalendarwidget.cpp.

References d.

01817 {
01818     Q_D(const QCalendarWidget);
01819     return (Qt::DayOfWeek)d->m_model->firstColumnDay();
01820 }

void QCalendarWidget::setFirstDayOfWeek ( Qt::DayOfWeek  dayOfWeek  ) 

Definition at line 1806 of file qcalendarwidget.cpp.

References d.

01807 {
01808     Q_D(QCalendarWidget);
01809     if ((Qt::DayOfWeek)d->m_model->firstColumnDay() == dayOfWeek)
01810         return;
01811 
01812     d->m_model->setFirstColumnDay(dayOfWeek);
01813     d->update();
01814 }

bool QCalendarWidget::isHeaderVisible (  )  const

Definition at line 1952 of file qcalendarwidget.cpp.

References d.

01953 {
01954     Q_D(const QCalendarWidget);
01955     return d->headerVisible;
01956 }

void QCalendarWidget::setHeaderVisible ( bool  show  ) 

Definition at line 1958 of file qcalendarwidget.cpp.

References d, and QWidget::updateGeometry().

01959 {
01960     Q_D(QCalendarWidget);
01961     d->headerVisible = show;
01962     (show)?d->headerBackground->show():d->headerBackground->hide();
01963     updateGeometry();
01964 }

Here is the call graph for this function:

bool QCalendarWidget::isGridVisible (  )  const

Definition at line 1757 of file qcalendarwidget.cpp.

References d.

01758 {
01759     Q_D(const QCalendarWidget);
01760     return d->m_view->showGrid();
01761 }

void QCalendarWidget::setGridVisible ( bool  show  ) 

Definition at line 1763 of file qcalendarwidget.cpp.

References d.

01764 {
01765     Q_D(QCalendarWidget);
01766     d->m_view->setShowGrid(show);
01767     d->m_view->viewport()->update();
01768     d->m_view->updateGeometry();
01769 }

QCalendarWidget::SelectionMode QCalendarWidget::selectionMode (  )  const

Definition at line 1787 of file qcalendarwidget.cpp.

References d, NoSelection, and SingleSelection.

01788 {
01789     Q_D(const QCalendarWidget);
01790     return d->m_view->readOnly ? QCalendarWidget::NoSelection : QCalendarWidget::SingleSelection;
01791 }

void QCalendarWidget::setSelectionMode ( SelectionMode  mode  ) 

Definition at line 1793 of file qcalendarwidget.cpp.

References d, and NoSelection.

01794 {
01795     Q_D(QCalendarWidget);
01796     d->m_view->readOnly = (mode == QCalendarWidget::NoSelection);
01797 }

QCalendarWidget::HorizontalHeaderFormat QCalendarWidget::horizontalHeaderFormat (  )  const

Definition at line 1693 of file qcalendarwidget.cpp.

References d.

Referenced by minimumSizeHint().

01694 {
01695     Q_D(const QCalendarWidget);
01696     return d->m_model->horizontalHeaderFormat;
01697 }

void QCalendarWidget::setHorizontalHeaderFormat ( HorizontalHeaderFormat  format  ) 

Definition at line 1682 of file qcalendarwidget.cpp.

References d.

01683 {
01684     Q_D(QCalendarWidget);
01685     if (d->m_model->horizontalHeaderFormat == format)
01686         return;
01687 
01688     d->m_model->setHorizontalHeaderFormat(format);
01689     d->m_view->viewport()->update();
01690     d->m_view->updateGeometry();
01691 }

QCalendarWidget::VerticalHeaderFormat QCalendarWidget::verticalHeaderFormat (  )  const

Definition at line 1717 of file qcalendarwidget.cpp.

References d, ISOWeekNumbers, and NoVerticalHeader.

Referenced by minimumSizeHint().

01718 {
01719     Q_D(const QCalendarWidget);
01720     bool shown = d->m_model->weekNumbersShown();
01721     if (shown)
01722         return QCalendarWidget::ISOWeekNumbers;
01723     return QCalendarWidget::NoVerticalHeader;
01724 }

void QCalendarWidget::setVerticalHeaderFormat ( VerticalHeaderFormat  format  ) 

Definition at line 1726 of file qcalendarwidget.cpp.

References d, ISOWeekNumbers, and QWidget::show().

Referenced by QCalendarPopup::QCalendarPopup().

01727 {
01728     Q_D(QCalendarWidget);
01729     bool show = false;
01730     if (format == QCalendarWidget::ISOWeekNumbers)
01731         show = true;
01732     if (d->m_model->weekNumbersShown() == show)
01733         return;
01734     d->m_model->setWeekNumbersShown(show);
01735     d->m_view->viewport()->update();
01736     d->m_view->updateGeometry();
01737 }

QTextCharFormat QCalendarWidget::headerTextFormat (  )  const

Returns the text char format for rendering the header.

Definition at line 1825 of file qcalendarwidget.cpp.

References d.

01826 {
01827     Q_D(const QCalendarWidget);
01828     return d->m_model->m_headerFormat;
01829 }

void QCalendarWidget::setHeaderTextFormat ( const QTextCharFormat format  ) 

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.

Definition at line 1838 of file qcalendarwidget.cpp.

References d.

01839 {
01840     Q_D(QCalendarWidget);
01841     d->m_model->m_headerFormat = format;
01842     d->m_view->viewport()->update();
01843     d->m_view->updateGeometry();
01844 }

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

Returns the text char format for rendering of day in the week dayOfWeek.

See also:
headerTextFormat()

Definition at line 1851 of file qcalendarwidget.cpp.

References d.

01852 {
01853     Q_D(const QCalendarWidget);
01854     return d->m_model->m_dayFormats.value(dayOfWeek);
01855 }

void QCalendarWidget::setWeekdayTextFormat ( Qt::DayOfWeek  dayOfWeek,
const QTextCharFormat format 
)

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.

See also:
setHeaderTextFormat()

Definition at line 1864 of file qcalendarwidget.cpp.

References d.

01865 {
01866     Q_D(QCalendarWidget);
01867     d->m_model->m_dayFormats[dayOfWeek] = format;
01868     d->m_view->viewport()->update();
01869     d->m_view->updateGeometry();
01870 }

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

Returns a QMap from QDate to QTextCharFormat showing all dates that use a special format that alters their rendering.

Definition at line 1876 of file qcalendarwidget.cpp.

References d.

01877 {
01878     Q_D(const QCalendarWidget);
01879     return d->m_model->m_dateFormats;
01880 }

QTextCharFormat QCalendarWidget::dateTextFormat ( const QDate date  )  const

Returns a QTextCharFormat for date. The char format can be be empty if the date is not renderd specially.

Definition at line 1886 of file qcalendarwidget.cpp.

References d.

01887 {
01888     Q_D(const QCalendarWidget);
01889     return d->m_model->m_dateFormats.value(date);
01890 }

void QCalendarWidget::setDateTextFormat ( const QDate date,
const QTextCharFormat format 
)

Sets format to render date.

Definition at line 1895 of file qcalendarwidget.cpp.

References d.

01896 {
01897     Q_D(QCalendarWidget);
01898     d->m_model->m_dateFormats[date] = format;
01899     d->m_view->viewport()->update();
01900     d->m_view->updateGeometry();
01901 }

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

Reimplemented from QWidget.

Definition at line 1969 of file qcalendarwidget.cpp.

References QEvent::ApplicationFontChange, d, QWidget::event(), and QEvent::FontChange.

Referenced by keyPressEvent(), mousePressEvent(), and resizeEvent().

01970 {
01971     Q_D(QCalendarWidget);
01972     if (event->type() == QEvent::FontChange || event->type() == QEvent::ApplicationFontChange) {
01973         d->updateHeader();
01974         d->m_view->updateGeometry();
01975     }
01976     return QWidget::event(event);
01977 }

Here is the call graph for this function:

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

Reimplemented from QWidget.

Definition at line 1982 of file qcalendarwidget.cpp.

References event(), QWidget::mousePressEvent(), QWidget::setAttribute(), QWidget::setFocus(), and Qt::WA_NoMouseReplay.

01983 {
01984     setAttribute(Qt::WA_NoMouseReplay);
01985     QWidget::mousePressEvent(event);
01986     setFocus();
01987 }

Here is the call graph for this function:

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

Reimplemented from QWidget.

Definition at line 1992 of file qcalendarwidget.cpp.

References d, event(), and QWidget::resizeEvent().

01993 {
01994     Q_D(QCalendarWidget);
01995     if(d->yearEdit->isVisible())
01996         d->_q_yearEditingFinished();
01997     QWidget::resizeEvent(event);
01998 }

Here is the call graph for this function:

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

Reimplemented from QWidget.

Definition at line 2003 of file qcalendarwidget.cpp.

References d, event(), Qt::Key_Escape, QWidget::keyReleaseEvent(), and yearShown().

02004 {
02005     Q_D(QCalendarWidget);
02006     if(d->yearEdit->isVisible()&& event->key() == Qt::Key_Escape)
02007     {
02008         d->yearEdit->setValue(yearShown());
02009         d->_q_yearEditingFinished();
02010         return;
02011     }
02012     QWidget::keyReleaseEvent(event);
02013 }

Here is the call graph for this function:

void QCalendarWidget::paintCell ( QPainter painter,
const QRect rect,
const QDate date 
) const [protected, virtual]

Paints the cell specified by the given date, using the given painter and rect.

Definition at line 1322 of file qcalendarwidget.cpp.

References d, and QWidget::rect().

01323 {
01324     Q_D(const QCalendarWidget);
01325     d->m_delegate->paintCell(painter, rect, date);
01326 }

Here is the call graph for this function:

void QCalendarWidget::setSelectedDate ( const QDate date  )  [slot]

Definition at line 1345 of file qcalendarwidget.cpp.

References d, QDate::isValid(), QDate::month(), and QDate::year().

Referenced by QCalendarPopup::QCalendarPopup(), and QCalendarPopup::setDate().

01346 {
01347     Q_D(QCalendarWidget);
01348     if (d->m_model->date == date && date == d->getCurrentDate())
01349         return;
01350 
01351     if (!date.isValid())
01352         return;
01353 
01354     d->m_model->setDate(date);
01355     d->update();
01356     QDate newDate = d->m_model->date;
01357     d->showMonth(newDate.year(), newDate.month());
01358 }

void QCalendarWidget::setDateRange ( const QDate min,
const QDate max 
) [slot]

Defines a date range by setting the minimumDate and maximumDate 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 the min or max parameters are not valid QDate objects, this function does nothing.

See also:
setMinimumDate(), setMaximumDate()

Definition at line 1634 of file qcalendarwidget.cpp.

References d, emit, QDate::isValid(), QDate::month(), selectionChanged(), and QDate::year().

01635 {
01636     Q_D(QCalendarWidget);
01637     if (d->m_model->minimumDate == min && d->m_model->maximumDate == max)
01638         return;
01639     if (!min.isValid() || !max.isValid())
01640         return;
01641 
01642     QDate minimum = min;
01643     QDate maximum = max;
01644     if (min > max) {
01645         minimum = max;
01646         maximum = min;
01647     }
01648 
01649     QDate oldDate = d->m_model->date;
01650     d->m_model->setRange(min, max);
01651     d->yearEdit->setMinimum(d->m_model->minimumDate.year());
01652     d->yearEdit->setMaximum(d->m_model->maximumDate.year());
01653     d->updateMonthMenu();
01654     QDate newDate = d->m_model->date;
01655     if (oldDate != newDate) {
01656         d->update();
01657         d->showMonth(newDate.year(), newDate.month());
01658         emit selectionChanged();
01659     }
01660 }

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

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 currentPageMonth() and currentPageYear() functions respectively.

See also:
yearShown(), monthShown(), showPreviousMonth(), showNextMonth(), showPreviousYear(), showNextYear()

Definition at line 1398 of file qcalendarwidget.cpp.

References d.

Referenced by showNextMonth(), showNextYear(), showPreviousMonth(), showPreviousYear(), showSelectedDate(), and showToday().

01399 {
01400     Q_D(QCalendarWidget);
01401     d->showMonth(year, month);
01402 }

void QCalendarWidget::showNextMonth (  )  [slot]

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

See also:
showPreviousMonth(), setCurrentPage(), setSelectedDate()

Definition at line 1411 of file qcalendarwidget.cpp.

References monthShown(), setCurrentPage(), and yearShown().

01412 {
01413     int year = yearShown();
01414     int month = monthShown();
01415     if (month == 12) {
01416         ++year;
01417         month = 1;
01418     } else {
01419         ++month;
01420     }
01421     setCurrentPage(year, month);
01422 }

void QCalendarWidget::showPreviousMonth (  )  [slot]

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

See also:
showNextMonth(), setCurrentPage(), setSelectedDate()

Definition at line 1431 of file qcalendarwidget.cpp.

References monthShown(), setCurrentPage(), and yearShown().

01432 {
01433     int year = yearShown();
01434     int month = monthShown();
01435     if (month == 1) {
01436         --year;
01437         month = 12;
01438     } else {
01439         --month;
01440     }
01441     setCurrentPage(year, month);
01442 }

void QCalendarWidget::showNextYear (  )  [slot]

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

See also:
showPreviousYear(), setCurrentPage(), setSelectedDate()

Definition at line 1452 of file qcalendarwidget.cpp.

References monthShown(), setCurrentPage(), and yearShown().

01453 {
01454     int year = yearShown();
01455     int month = monthShown();
01456     ++year;
01457     setCurrentPage(year, month);
01458 }

void QCalendarWidget::showPreviousYear (  )  [slot]

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

See also:
showNextYear(), setCurrentPage(), setSelectedDate()

Definition at line 1468 of file qcalendarwidget.cpp.

References monthShown(), setCurrentPage(), and yearShown().

01469 {
01470     int year = yearShown();
01471     int month = monthShown();
01472     --year;
01473     setCurrentPage(year, month);
01474 }

void QCalendarWidget::showSelectedDate (  )  [slot]

Shows the month of the selected date.

See also:
selectedDate(), setCurrentPage()

Definition at line 1481 of file qcalendarwidget.cpp.

References QDate::month(), selectedDate(), setCurrentPage(), and QDate::year().

01482 {
01483     QDate currentDate = selectedDate();
01484     setCurrentPage(currentDate.year(), currentDate.month());
01485 }

void QCalendarWidget::showToday (  )  [slot]

Shows the month of the today's date.

See also:
selectedDate(), setCurrentPage()

Definition at line 1492 of file qcalendarwidget.cpp.

References QDate::currentDate(), QDate::month(), setCurrentPage(), and QDate::year().

01493 {
01494     QDate currentDate = QDate::currentDate();
01495     setCurrentPage(currentDate.year(), currentDate.month());
01496 }

void QCalendarWidget::selectionChanged (  )  [signal]

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 using setSelectedDate().

See also:
selectedDate()

Referenced by setDateRange(), setMaximumDate(), and setMinimumDate().

void QCalendarWidget::clicked ( const QDate date  )  [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.

Referenced by QCalendarWidget().

void QCalendarWidget::activated ( const QDate date  )  [signal]

This signal is emitted whenever the user presses the Return or Enter key, the space bar or double-clicks a date in the calendar widget.

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

This signal is emitted when the currently shown month is changed. The new year and month are passed as parameters.

See also:
setCurrentPage()

QCalendarWidget::Q_PRIVATE_SLOT ( d_func()  ,
void   _q_slotChangeDate(const QDate &date, bool changeMonth) 
) [private]

void QCalendarWidget::_q_editingFinished (  )  [private]

Referenced by QCalendarWidget().

void void QCalendarWidget::_q_prevMonthClicked (  )  [private]

Referenced by QCalendarWidget().

void void void QCalendarWidget::_q_nextMonthClicked (  )  [private]

Referenced by QCalendarWidget().

void void void void QCalendarWidget::_q_yearEditingFinished (  )  [private]

Referenced by QCalendarWidget().

void void void void void QCalendarWidget::_q_yearClicked (  )  [private]

Referenced by QCalendarWidget().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:57:15 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1