Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QCalendarWidget Class Reference
[QtGui module]

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

 #include <QCalendarWidget>

Inherits QWidget.

This class was introduced in Qt 4.2.

Public Types

Properties

  • 55 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

  • 195 public functions inherited from QWidget
  • 29 public functions inherited from QObject
  • 12 public functions inherited from QPaintDevice

Public Slots

  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

  • virtual void paintCell ( QPainter * painter, const QRect & rect, const QDate & date ) const
  • 38 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 5 static public members inherited from QObject
  • 1 protected slot inherited from QWidget

Detailed Description

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. 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, and QTextCharFormat.


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 also horizontalHeaderFormat() and VerticalHeaderFormat.

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 also selectionMode.

enum QCalendarWidget::VerticalHeaderFormat

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

ConstantValueDescription
QCalendarWidget::ISOWeekNumbers1The header displays a ISO week numbers QDate::weekNumber().
QCalendarWidget::NoVerticalHeader0The header is hidden.

See also verticalHeaderFormat() and HorizontalHeaderFormat.


Property Documentation

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::DayOfWeek firstDayOfWeek () const
  • void setFirstDayOfWeek ( 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:

  • bool isGridVisible () const
  • void setGridVisible ( bool show )

headerVisible : bool

This property holds whether the Header is shown or not.

When this property is set to true 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.

The default value is true.

Access functions:

  • bool isHeaderVisible () const
  • void setHeaderVisible ( bool show )

horizontalHeaderFormat : HorizontalHeaderFormat

This property holds the format of the horizontal header.

The default value is QCalendarWidget::ShortDayNames.

Access functions:

  • HorizontalHeaderFormat horizontalHeaderFormat () const
  • void setHorizontalHeaderFormat ( 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 the QDate class can handle.

When setting a maximum date, the minimumDate and selectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a valid QDate object, the setMaximumDate() function does nothing.

Access functions:

  • QDate maximumDate () const
  • void setMaximumDate ( const QDate & date )

See also setDateRange().

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 the QDate class can handle.

When setting a minimum date, the maximumDate and selectedDate properties are adjusted if the selection range becomes invalid. If the provided date is not a valid QDate object, the setMinimumDate() function does nothing.

Access functions:

  • QDate minimumDate () const
  • void setMinimumDate ( const QDate & date )

See also setDateRange().

selectedDate : QDate

This property holds the currently selected date.

The selected date must be within the date range specified by the minimumDate and maximumDate properties. By default, the selected date is the current date.

Access functions:

  • QDate selectedDate () const
  • void setSelectedDate ( const QDate & date )

See also setDateRange().

selectionMode : SelectionMode

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

When this property is set to SingleSelection, 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 to NoSelection, 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 to NoSelection will still be the selected date of the calendar.

The default value is SingleSelection.

Access functions:

  • SelectionMode selectionMode () const
  • void setSelectionMode ( SelectionMode mode )

verticalHeaderFormat : VerticalHeaderFormat

This property holds the format of the vertical header.

The default value is QCalendarWidget::ISOWeekNumber.

Access functions:

  • VerticalHeaderFormat verticalHeaderFormat () const
  • void setVerticalHeaderFormat ( VerticalHeaderFormat format )

Member Function Documentation

QCalendarWidget::QCalendarWidget ( QWidget * parent = 0 )

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

QCalendarWidget::~QCalendarWidget ()

Destroys the calendar widget.

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::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.

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

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.

See also setDateTextFormat().

QTextCharFormat QCalendarWidget::dateTextFormat ( const QDate & date ) const

This is an overloaded member function, provided for convenience.

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

QTextCharFormat QCalendarWidget::headerTextFormat () const

Returns the text char format for rendering the header.

See also setHeaderTextFormat().

int QCalendarWidget::monthShown () const

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

See also yearShown() and setCurrentPage().

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

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

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

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(), and showNextYear().

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() and setMaximumDate().

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

Sets format to render date.

See also dateTextFormat().

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.

See also headerTextFormat().

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 weekdayTextFormat() and setHeaderTextFormat().

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

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

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

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

void QCalendarWidget::showSelectedDate ()   [slot]

Shows the month of the selected date.

See also selectedDate() and setCurrentPage().

void QCalendarWidget::showToday ()   [slot]

Shows the month of the today's date.

See also selectedDate() and setCurrentPage().

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

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

See also setWeekdayTextFormat() and headerTextFormat().

int QCalendarWidget::yearShown () const

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

See also monthShown() and setCurrentPage().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web