×
Namespaces

Variants
Actions

Archived:How to use QDateTimeEdit

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

This code snippet demonstrates how to use Qt's QDateTimeEdit class for editing date and time.

Article Metadata
Tested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QDateTimeEdit
Created: james1980 (17 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

QDateTimeEdit allows the user to edit dates and time 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. Date and time appear in accordance with the format set using the function setDisplayFormat().

Contents

Various Function

  • This property setMinimumDate(const QDate & min)/ setMinimumTime( const QTime & min ) holds the minimum date/minimum time of the date time edit and like wise for MaximumTime[1]
QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
QDateTimeEdit *timeEdit = new QDateTimeEdit(QTime::currentTime());
dateEdit->setMinimumDate(QDate::currentDate().addYears(-5));
timeEdit->setMinimumTime(QTime::currentTime().addSecs(-3600));
  • This property holds the current timespec used by the date time edit.
timeEdit->setTimeSpec(Qt::UTC||Qt::Localtime);
  • This property holds the format used to display the time/date of the date time edit.
dateEdit->setDisplayFormat("dd/MM/yyyy");
dateEdit->setDisplayFormat("dd-MM-yyyy");
DateEdit1.JPG

Code Snippet

Source File

#include "dateedit.h"
#include <QDate>
#include <QDateEdit>
#include <QVBoxLayout>
dateedit::dateedit(QWidget *parent)
: QWidget(parent)
{
layout = new QVBoxLayout(this);
date = new QDate;
time = new QTime;
dateEdit = new QDateTimeEdit(QDate::currentDate());
dateEdit->setMinimumDate(QDate::currentDate().addYears(-5));
dateEdit->setMaximumDate(QDate::currentDate().addYears(5));
dateEdit->setDisplayFormat("yyyy.MM.dd");
connect(dateEdit,SIGNAL(dateChanged(date)),dateEdit,SLOT(setDate(date)));
timeEdit = new QDateTimeEdit(QTime::currentTime());
timeEdit->setMinimumTime(QTime::currentTime().addSecs(-3600));
timeEdit->setMaximumTime(QTime::currentTime().addSecs(3600));
connect(timeEdit,SIGNAL(timeChanged(time)),timeEdit,SLOT(setTime(date)));
layout->addWidget(timeEdit);
layout->addWidget(dateEdit);
setLayout(layout);
}
 
dateedit::~dateedit()
{
delete *date ;
delete *time;
delete *dateEdit;
delete *timeEdit;
}

Header File

#ifndef DATEEDIT_H
#define DATEEDIT_H
 
#include <QtGui/QWidget>
#include "ui_dateedit.h"
#include <QDate>
#include <QDateEdit>
#include <QVBoxLayout>
class dateedit : public QWidget
{
Q_OBJECT
 
public:
dateedit(QWidget *parent = 0);
~dateedit();
 
private:
QVBoxLayout *layout;
QDate *date ;
QTime *time;
QDateTimeEdit *dateEdit;
QDateTimeEdit *timeEdit;
};
 
#endif // DATEEDIT_H

Screenshot

Dateedit.jpg

This page was last modified on 11 October 2012, at 04:14.
98 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×