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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QDateTimeEdit Class Reference
[QtGui module]

The QDateTimeEdit class provides a widget for editing dates and times. More...

 #include <QDateTimeEdit>

Inherits QAbstractSpinBox.

Inherited by QDateEdit and QTimeEdit.


Public Types

enum Section { NoSection, AmPmSection, MSecSection, SecondSection, ..., YearSection }
flags Sections

Properties


Public Functions

QDateTimeEdit ( QWidget * parent = 0 )
QDateTimeEdit ( const QDateTime & datetime, QWidget * parent = 0 )
QDateTimeEdit ( const QDate & date, QWidget * parent = 0 )
QDateTimeEdit ( const QTime & time, QWidget * parent = 0 )
bool calendarPopup () const
QCalendarWidget * calendarWidget () const
void clearMaximumDate ()
void clearMaximumDateTime ()
void clearMaximumTime ()
void clearMinimumDate ()
void clearMinimumDateTime ()
void clearMinimumTime ()
Section currentSection () const
int currentSectionIndex () const
QDate date () const
QDateTime dateTime () const
QString displayFormat () const
Sections displayedSections () const
QDate maximumDate () const
QDateTime maximumDateTime () const
QTime maximumTime () const
QDate minimumDate () const
QDateTime minimumDateTime () const
QTime minimumTime () const
Section sectionAt ( int index ) const
int sectionCount () const
QString sectionText ( Section section ) const
void setCalendarPopup ( bool enable )
void setCalendarWidget ( QCalendarWidget * calendarWidget )
void setCurrentSection ( Section section )
void setCurrentSectionIndex ( int index )
void setDateRange ( const QDate & min, const QDate & max )
void setDateTimeRange ( const QDateTime & min, const QDateTime & max )
void setDisplayFormat ( const QString & format )
void setMaximumDate ( const QDate & max )
void setMaximumDateTime ( const QDateTime & dt )
void setMaximumTime ( const QTime & max )
void setMinimumDate ( const QDate & min )
void setMinimumDateTime ( const QDateTime & dt )
void setMinimumTime ( const QTime & min )
void setSelectedSection ( Section section )
void setTimeRange ( const QTime & min, const QTime & max )
void setTimeSpec ( Qt::TimeSpec spec )
QTime time () const
Qt::TimeSpec timeSpec () const

Reimplemented Public Functions

virtual void clear ()
virtual bool event ( QEvent * event )
virtual QSize sizeHint () const
virtual void stepBy ( int steps )

Public Slots

void setDate ( const QDate & date )
void setDateTime ( const QDateTime & dateTime )
void setTime ( const QTime & time )

Signals

void dateChanged ( const QDate & date )
void dateTimeChanged ( const QDateTime & datetime )
void timeChanged ( const QTime & time )

Protected Functions

virtual QDateTime dateTimeFromText ( const QString & text ) const
void initStyleOption ( QStyleOptionSpinBox * option ) const
virtual QString textFromDateTime ( const QDateTime & dateTime ) const

Reimplemented Protected Functions

virtual void fixup ( QString & input ) const
virtual void focusInEvent ( QFocusEvent * event )
virtual bool focusNextPrevChild ( bool next )
virtual void keyPressEvent ( QKeyEvent * event )
virtual void mousePressEvent ( QMouseEvent * event )
virtual void paintEvent ( QPaintEvent * event )
virtual StepEnabled stepEnabled () const
virtual QValidator::State validate ( QString & text, int & pos ) const
virtual void wheelEvent ( QWheelEvent * event )

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 QDateTimeEdit class provides a widget for editing dates and times.

QDateTimeEdit allows the user to edit dates by using the keyboard or the arrow keys to increase and decrease date and time values. The arrow keys can be used to move from section to section within the QDateTimeEdit box. Dates and times appear in accordance with the format set; see setDisplayFormat().

 QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
 dateEdit->setMinimumDate(QDate::currentDate().addDays(-365));
 dateEdit->setMaximumDate(QDate::currentDate().addDays(365));
 dateEdit->setDisplayFormat("yyyy.MM.dd");

Here we've created a new QDateTimeEdit object initialized with today's date, and restricted the valid date range to today plus or minus 365 days. We've set the order to month, day, year.

The minimum value for QDateTimeEdit is 14 September 1752, and 2 January 4713BC for QDate. You can change this by calling setMinimumDate(), setMaximumDate(), setMinimumTime(), and setMaximumTime().

Using a Pop-up Calendar Widget

QDateTimeEdit can be configured to allow a QCalendarWidget to be used to select dates. This is enabled by setting the calendarPopup property. Additionally, you can supply a custom calendar widget for use as the calendar pop-up by calling the setCalendarWidget() function. The existing calendar widget can be retrieved with calendarWidget().

Screenshot of a Windows XP style date time editing widgetA date time editing widget shown in the Windows XP widget style.
Screenshot of a Macintosh style date time editing widgetA date time editing widget shown in the Macintosh widget style.
Screenshot of a Plastique style date time editing widgetA date time editing widget shown in the Plastique widget style.

See also QDateEdit, QTimeEdit, QDate, and QTime.


Member Type Documentation

enum QDateTimeEdit::Section
flags QDateTimeEdit::Sections

ConstantValue
QDateTimeEdit::NoSection0x0000
QDateTimeEdit::AmPmSection0x0001
QDateTimeEdit::MSecSection0x0002
QDateTimeEdit::SecondSection0x0004
QDateTimeEdit::MinuteSection0x0008
QDateTimeEdit::HourSection0x0010
QDateTimeEdit::DaySection0x0100
QDateTimeEdit::MonthSection0x0200
QDateTimeEdit::YearSection0x0400

The Sections type is a typedef for QFlags<Section>. It stores an OR combination of Section values.


Property Documentation

calendarPopup : bool

This property holds the current calender pop-up showing mode.

The calendar pop-up will be shown upon clicking the arrow button. This property is valid only if there is a valid date display format.

This property was introduced in Qt 4.2.

Access functions:

bool calendarPopup () const
void setCalendarPopup ( bool enable )

See also setDisplayFormat().

currentSection : Section

This property holds the current section of the spinbox setCurrentSection().

Access functions:

Section currentSection () const
void setCurrentSection ( Section section )

currentSectionIndex : int

This property holds the current section index of the spinbox.

If the format is 'yyyy/MM/dd', the displayText is '2001/05/21' and the cursorPosition is 5 currentSectionIndex returns 1. If the cursorPosition is 3 currentSectionIndex is 0 etc.

setCurrentSection()

This property was introduced in Qt 4.3.

Access functions:

int currentSectionIndex () const
void setCurrentSectionIndex ( int index )

See also currentSection().

date : QDate

This property holds the QDate that is set in the QDateTimeEdit.

By default, this property contains a date that refers to January 1, 2000.

Access functions:

QDate date () const
void setDate ( const QDate & date )

Notifier signal:

void dateChanged ( const QDate & date )

See also time and dateTime.

dateTime : QDateTime

This property holds the QDateTime that is set in the QDateTimeEdit.

When setting this property the timespec of the QDateTimeEdit remains the same and the timespec of the new QDateTime is ignored.

By default, this property contains a date that refers to January 1, 2000 and a time of 00:00:00 and 0 milliseconds.

Access functions:

QDateTime dateTime () const
void setDateTime ( const QDateTime & dateTime )

Notifier signal:

void dateTimeChanged ( const QDateTime & datetime )

See also date and time.

displayFormat : QString

This property holds the format used to display the time/date of the date time edit.

This format is the same as the one used described in QDateTime::toString() and QDateTime::fromString()

Example format strings(assuming that the date is 2nd of July 1969):

FormatResult
dd.MM.yyyy02.07.1969
MMM d yyJul 2 69
MMMM d yyJuly 2 69

Note that if you specify a two digit year, it will be interpreted to be in the century in which the date time edit was initialized. The default century is the 21 (2000-2099).

If you specify an invalid format the format will not be set.

Access functions:

QString displayFormat () const
void setDisplayFormat ( const QString & format )

See also QDateTime::toString() and displayedSections().

displayedSections : const Sections

This property holds the currently displayed fields of the date time edit.

Returns a bit set of the displayed sections for this format. setDisplayFormat(), displayFormat()

Access functions:

Sections displayedSections () const

maximumDate : QDate

This property holds the maximum date of the date time edit.

When setting this property the minimumDate is adjusted if necessary to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.

By default, this property contains a date that refers to December 31, 7999.

Access functions:

QDate maximumDate () const
void setMaximumDate ( const QDate & max )
void clearMaximumDate ()

See also minimumDate, minimumTime, maximumTime, and setDateRange().

maximumDateTime : QDateTime

This property holds the maximum datetime of the date time edit.

When setting this property the minimumDateTime() is adjusted if necessary to ensure that the range remains valid. If the datetime is not a valid QDateTime object, this function does nothing.

The default maximumDateTime can be restored with clearMaximumDateTime().

By default, this property contains a date that refers to 31 December, 7999 and a time of 23:59:59 and 999 milliseconds.

This property was introduced in Qt 4.4.

Access functions:

QDateTime maximumDateTime () const
void setMaximumDateTime ( const QDateTime & dt )
void clearMaximumDateTime ()

See also minimumDateTime(), minimumTime(), maximumTime(), minimumDate(), maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), clearMinimumDateTime(), clearMinimumDate(), clearMaximumDate(), clearMinimumTime(), and clearMaximumTime().

maximumTime : QTime

This property holds the maximum time of the date time edit.

When setting this property, the minimumTime is adjusted if necessary to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.

By default, this property contains a time of 23:59:59 and 999 milliseconds.

Access functions:

QTime maximumTime () const
void setMaximumTime ( const QTime & max )
void clearMaximumTime ()

See also minimumTime, minimumDate, maximumDate, and setTimeRange().

minimumDate : QDate

This property holds the minimum date of the date time edit.

When setting this property the maximumDate is adjusted if necessary, to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing.

By default, this property contains a date that refers to September 14, 1752. The minimum date must be at least the first day in year 100, otherwise setMinimumDate() has no effect.

Access functions:

QDate minimumDate () const
void setMinimumDate ( const QDate & min )
void clearMinimumDate ()

See also minimumTime(), maximumTime(), and setDateRange().

minimumDateTime : QDateTime

This property holds the minimum datetime of the date time edit.

When setting this property the maximumDateTime() is adjusted if necessary to ensure that the range remains valid. If the datetime is not a valid QDateTime object, this function does nothing.

The default minimumDateTime can be restored with clearMinimumDateTime()

By default, this property contains a date that refers to September 14, 1752 and a time of 00:00:00 and 0 milliseconds.

This property was introduced in Qt 4.4.

Access functions:

QDateTime minimumDateTime () const
void setMinimumDateTime ( const QDateTime & dt )
void clearMinimumDateTime ()

See also maximumDateTime(), minimumTime(), maximumTime(), minimumDate(), maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), clearMaximumDateTime(), clearMinimumDate(), clearMaximumDate(), clearMinimumTime(), and clearMaximumTime().

minimumTime : QTime

This property holds the minimum time of the date time edit.

When setting this property the maximumTime is adjusted if necessary, to ensure that the range remains valid. If the time is not a valid QTime object, this function does nothing.

By default, this property contains a time of 00:00:00 and 0 milliseconds.

Access functions:

QTime minimumTime () const
void setMinimumTime ( const QTime & min )
void clearMinimumTime ()

See also maximumTime, minimumDate, maximumDate, and setTimeRange().

sectionCount : const int

This property holds the number of sections displayed. If the format is 'yyyy/yy/yyyy', sectionCount returns 3.

This property was introduced in Qt 4.3.

Access functions:

int sectionCount () const

time : QTime

This property holds the QTime that is set in the QDateTimeEdit.

By default, this property contains a time of 00:00:00 and 0 milliseconds.

Access functions:

QTime time () const
void setTime ( const QTime & time )

Notifier signal:

void timeChanged ( const QTime & time )

See also date and dateTime.

timeSpec : Qt::TimeSpec

This property holds the current timespec used by the date time edit.

This property was introduced in Qt 4.4.

Access functions:

Qt::TimeSpec timeSpec () const
void setTimeSpec ( Qt::TimeSpec spec )

Member Function Documentation

QDateTimeEdit::QDateTimeEdit ( QWidget * parent = 0 )

Constructs an empty date time editor with a parent.

QDateTimeEdit::QDateTimeEdit ( const QDateTime & datetime, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to datetime.

QDateTimeEdit::QDateTimeEdit ( const QDate & date, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to date.

QDateTimeEdit::QDateTimeEdit ( const QTime & time, QWidget * parent = 0 )

Constructs an empty date time editor with a parent. The value is set to time.

QCalendarWidget * QDateTimeEdit::calendarWidget () const

Returns the calendar widget for the editor if calendarPopup is set to true and (sections() & DateSections_Mask) != 0.

This function creates and returns a calendar widget if none has been set.

This function was introduced in Qt 4.4.

See also setCalendarWidget().

void QDateTimeEdit::clear ()   [virtual]

Reimplemented from QAbstractSpinBox::clear().

void QDateTimeEdit::dateChanged ( const QDate & date )   [signal]

This signal is emitted whenever the date is changed. The new date is passed in date.

void QDateTimeEdit::dateTimeChanged ( const QDateTime & datetime )   [signal]

This signal is emitted whenever the date or time is changed. The new date and time is passed in datetime.

QDateTime QDateTimeEdit::dateTimeFromText ( const QString & text ) const   [virtual protected]

Returns an appropriate datetime for the given text.

This virtual function is used by the datetime edit whenever it needs to interpret text entered by the user as a value.

See also textFromDateTime() and validate().

bool QDateTimeEdit::event ( QEvent * event )   [virtual]

Reimplemented from QObject::event().

void QDateTimeEdit::fixup ( QString & input ) const   [virtual protected]

Reimplemented from QAbstractSpinBox::fixup().

void QDateTimeEdit::focusInEvent ( QFocusEvent * event )   [virtual protected]

Reimplemented from QWidget::focusInEvent().

bool QDateTimeEdit::focusNextPrevChild ( bool next )   [virtual protected]

Reimplemented from QWidget::focusNextPrevChild().

void QDateTimeEdit::initStyleOption ( QStyleOptionSpinBox * option ) const   [protected]

Initialize option with the values from this QDataTimeEdit. This method is useful for subclasses when they need a QStyleOptionSpinBox, but don't want to fill in all the information themselves.

See also QStyleOption::initFrom().

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

Reimplemented from QWidget::keyPressEvent().

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

Reimplemented from QWidget::mousePressEvent().

void QDateTimeEdit::paintEvent ( QPaintEvent * event )   [virtual protected]

Reimplemented from QWidget::paintEvent().

Section QDateTimeEdit::sectionAt ( int index ) const

Returns the Section at index.

If the format is 'yyyy/MM/dd', sectionAt(0) returns YearSection, sectionAt(1) returns MonthSection, and sectionAt(2) returns YearSection,

This function was introduced in Qt 4.3.

QString QDateTimeEdit::sectionText ( Section section ) const

Returns the text from the given section.

See also currentSection().

void QDateTimeEdit::setCalendarWidget ( QCalendarWidget * calendarWidget )

Sets the given calendarWidget as the widget to be used for the calendar pop-up. The editor does not automatically take ownership of the calendar widget.

This function was introduced in Qt 4.4.

See also calendarWidget() and calendarPopup.

void QDateTimeEdit::setDateRange ( const QDate & min, const QDate & max )

Convenience function to set minimum and maximum date with one function call.

 setDateRange(min, max);

is analogous to:

 setMinimumDate(min);
 setMaximumDate(max);

If either min or max are not valid, this function does nothing.

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QDate::isValid().

void QDateTimeEdit::setDateTimeRange ( const QDateTime & min, const QDateTime & max )

Convenience function to set minimum and maximum date time with one function call.

 setDateTimeRange(min, max);

is analogous to:

 setMinimumDateTime(min);
 setMaximumDateTime(max);

If either min or max are not valid, this function does nothing.

This function was introduced in Qt 4.4.

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QDateTime::isValid().

void QDateTimeEdit::setSelectedSection ( Section section )

Selects section. If section doesn't exist in the currently displayed sections this function does nothing. If section is NoSection this function will unselect all text in the editor. Otherwise this function will move the cursor and the current section to the selected section.

This function was introduced in Qt 4.2.

See also currentSection().

void QDateTimeEdit::setTimeRange ( const QTime & min, const QTime & max )

Convenience function to set minimum and maximum time with one function call.

 setTimeRange(min, max);

is analogous to:

 setMinimumTime(min);
 setMaximumTime(max);

If either min or max are not valid, this function does nothing.

See also setMinimumDate(), maximumDate(), setMaximumDate(), clearMinimumDate(), setMinimumTime(), maximumTime(), setMaximumTime(), clearMinimumTime(), and QTime::isValid().

QSize QDateTimeEdit::sizeHint () const   [virtual]

Reimplemented from QWidget::sizeHint().

void QDateTimeEdit::stepBy ( int steps )   [virtual]

Reimplemented from QAbstractSpinBox::stepBy().

StepEnabled QDateTimeEdit::stepEnabled () const   [virtual protected]

Reimplemented from QAbstractSpinBox::stepEnabled().

QString QDateTimeEdit::textFromDateTime ( const QDateTime & dateTime ) const   [virtual protected]

This virtual function is used by the date time edit whenever it needs to display dateTime.

If you reimplement this, you may also need to reimplement validate().

See also dateTimeFromText() and validate().

void QDateTimeEdit::timeChanged ( const QTime & time )   [signal]

This signal is emitted whenever the time is changed. The new time is passed in time.

QValidator::State QDateTimeEdit::validate ( QString & text, int & pos ) const   [virtual protected]

Reimplemented from QAbstractSpinBox::validate().

void QDateTimeEdit::wheelEvent ( QWheelEvent * event )   [virtual protected]

Reimplemented from QWidget::wheelEvent().

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

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