Archived:How to use QCalendar
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QCalendar, Push Button
Created: (07 Jan 2009)
Last edited: nayan_trivedi
(11 Sep 2009)
Overview
This code snippet demonstrates how to calendar widget in Qt for S60.
Preconditions
- Install latest Qt for S60 see Qt for S60 - Installation packages
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
- Download Qt creator IDE 4.5: http://www.qtsoftware.com/downloads
Various Functions
- This property holds the format of the vertical header.
QCalendarWidget *calendar = new QCalendarWidget; calendar->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
- This property holds whether the date edit popup is enabled.When the widget is focus and then press any non-modifier key will cause a date edit to popup.
QCalendarWidget *calendar = new QCalendarWidget; calendar->setDateEditEnabled(1);
- Property holds a value identifying the day displayed in the first column.
QCalendarWidget *calendar = new QCalendarWidget; calendar->setFirstDayOfWeek(Qt::Wednesday);
Source File
#include <QCalendarWidget>
#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QWindowsStyle>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
QPushButton *nextyrbutton = new QPushButton("Next Year");
QPushButton *prevyrbutton = new QPushButton("Prev Year");
QCalendarWidget *calendar = new QCalendarWidget;
QObject::connect(nextyrbutton,SIGNAL(clicked()),calendar,SLOT(showNextYear()));
QObject::connect(prevyrbutton,SIGNAL(clicked()),calendar,SLOT(showPreviousYear()));
layout->addWidget(calendar);
layout->addWidget(prevyrbutton);
layout->addWidget(nextyrbutton);
calendar->setGridVisible(true);
win->setLayout(layout);
win->showNormal();
return app.exec();
}
- In the above example only two function for displaying next and previous year are used but there are many other function like showNextMonth,show PreviousMonth,showToday etc...

