A date picker. More...
#include <Wt/WDatePicker>
Public Member Functions | |
WDatePicker (WContainerWidget *parent=0) | |
Create a new date picker. | |
WDatePicker (bool i18n, WContainerWidget *parent=0) | |
Create a new date picker. | |
WDatePicker (WInteractWidget *displayWidget, WLineEdit *forEdit, bool i18n=false, WContainerWidget *parent=0) | |
Create a new date picker for existing line edit and with custom display widget. | |
void | setFormat (const WString &format) |
Sets the format used for parsing or writing the date in the line edit. | |
const WString & | format () const |
Returns the format. | |
WCalendar * | calendar () const |
The calendar widget. | |
WLineEdit * | lineEdit () const |
The line edit. | |
WInteractWidget * | displayWidget () const |
The display widget. | |
WDate | date () const |
The current date. | |
void | setDate (const WDate &date) |
Sets the current date. | |
void | setEnabled (bool enabled) |
Sets whether the widget is enabled. | |
virtual void | setDisabled (bool disabled) |
Sets whether the widget is disabled. | |
void | setHidden (bool hidden) |
Hide/unhide the widget. |
A date picker.
A date picker shows a line edit and an icon which when clicked popups a WCalendar for editing the date. Any date entered in the line edit is reflected in the calendar, and vice-versa.
Each of these widgets may be accessed individually (lineEdit(), calendar(), and displayWidget()) and there is a constructor that allows you to specify an existing line edit and display widget.
The date format used by default is "dd/MM/yyyy"
and can be changed using setFormat(). At any time, the date set may be read using date(), or can be changed using setDate().
Usage example:
Wt::WDatePicker *picker = new Wt::WDatePicker(this); picker->setFormat("dd-MM-yyyy"); picker->setDate(Wt::WDate(1976, 6, 14));
The date picker is styled by the current CSS theme. The look can be overridden using the Wt-datepicker
and Wt-outset
CSS class; the calendar itself can be styled as documented in WCalendar.
![]() Example of a WDatePicker (default theme) | ![]() Example of a WDatePicker (polished theme) |
Wt::WDatePicker::WDatePicker | ( | WContainerWidget * | parent = 0 ) |
Create a new date picker.
This constructor creates a line edit with an icon that leads to a popup calendar. A WDateValidator is configured for the line edit.
Wt::WDatePicker::WDatePicker | ( | bool | i18n, |
WContainerWidget * | parent = 0 |
||
) |
Create a new date picker.
This constructor creates a line edit with an icon that leads to a popup calendar. A WDateValidator is configured for the line edit.
i18n
is passed to the WCalendar constructor.
Wt::WDatePicker::WDatePicker | ( | WInteractWidget * | displayWidget, |
WLineEdit * | forEdit, | ||
bool | i18n = false , |
||
WContainerWidget * | parent = 0 |
||
) |
Create a new date picker for existing line edit and with custom display widget.
The displayWidget
is a button or image which much be clicked to open the date picker. This widget will become owned by the picker.
The forEdit
argument is the lineEdit that works in conjunction with the date picker. This widget does not become part of the date picker, and may be located anywhere else.
i18n
is passed to the WCalendar constructor.
WCalendar* Wt::WDatePicker::calendar | ( | ) | const [inline] |
The calendar widget.
Returns the calendar widget.
WDate Wt::WDatePicker::date | ( | ) | const |
The current date.
Reads the current date from the lineEdit().
Returns an invalid date (for which WDate::isValid() returns false
) if the date could not be parsed using the current format().
WInteractWidget* Wt::WDatePicker::displayWidget | ( | ) | const [inline] |
The display widget.
Returns the widget which is displayed to activate the calendar.
const WString& Wt::WDatePicker::format | ( | ) | const [inline] |
Returns the format.
WLineEdit* Wt::WDatePicker::lineEdit | ( | ) | const [inline] |
The line edit.
Returns the line edit which works in conjunction with this date picker.
void Wt::WDatePicker::setDate | ( | const WDate & | date ) |
void Wt::WDatePicker::setDisabled | ( | bool | disabled ) | [virtual] |
Sets whether the widget is disabled.
Enables or disables the widget (including all its descendant widgets). setDisabled(false) will enable this widget and all descendant widgets that are not disabled. A widget is only enabled if it and all its ancestors in the widget tree are disabled.
Reimplemented from Wt::WCompositeWidget.
void Wt::WDatePicker::setEnabled | ( | bool | enabled ) |
Sets whether the widget is enabled.
This is the oppositie of setDisabled().
void Wt::WDatePicker::setFormat | ( | const WString & | format ) |
Sets the format used for parsing or writing the date in the line edit.
Sets the format used for representing the date in the line edit. If the line edit has a WDateValidator configured for it, then also there the format is updated.
The default format is 'dd/MM/yyyy'
.