How to create a Custom Calendar
English Български
Pre-Requisites
- Basic_Qt_Programming_Tutorial [qt.io]
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
- How to use signals and slots [developer.qt.nokia.com]
- Counting_Clicks_for_Qt_Widgets [qt.io]
- How_to_create_a_custom_calender_widget [qt.io]