How to create a Custom Calendar

From Qt Wiki
Revision as of 15:43, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

English Български

Pre-Requisites

This calendar widget is a Composite widget comprising of a QToolButton,QLabel and QCalendarWidget.

Now create a QtGui Application by selecting File-New-Qt Widget Project-Qt Gui Application from the Qt Creator.

The above procedure will create a project consisting of four files with the user defined class name:

  • main.cpp
  • calendardialog.h
  • calendardialog.cpp
  • calendardialog.ui

Creating a Custom Calendar by Editing the files

Name the class with the Choice Name.Current class Name is Calendar.

open the calendardialog.ui, from the Designer view, Drag and drop the following controls.

Four tool buttons. yearBackButton, yearFrontButton, MonthBackButton, MonthFrontButton
Two labels, Titlelabel, DateLabel,
Three horizontal spacers,
One Button OkButton, and a calendar widget. calendarWidget

Now open the calendardialog.h and edit,

add the required slots to the calendardialog.h file.

calendardialog.h

edit the corresponding calendardialog.cpp, connect and implement the slots like below.

calendardialog.cpp

The UI file looks like this in the editable xml file format.

calendardialog.ui

Finally Create an instance of the Calendar class in main.cpp and call show() method before entering the event loop
by calling a.exec()

main.cpp

With the above example files one can easily create a custom calendar widget.

See also

Categories: