Qt Signal Slot Const Reference

Thanks to C11 lambdas and Qt’s ongoing evolution, these short slots can be replaced by a more succinct syntax. This avoids having to declare a method in your class declaration and shortens your implementation code. Both desirable goals! Let’s take a look. Getting rid of SIGNAL and SLOT macros. QtCore.SIGNAL and QtCore.SLOT macros allow Python to interface with Qt signal and slot delivery mechanisms. This is the old way of using signals and slots. The example below uses the well known clicked signal from a QPushButton. The connect method has a non python-friendly syntax. It is necessary to inform the object, its signal (via macro. A developer can choose to connect to a signal by creating a function (a slot) and calling the connect function to relate the signal to the slot. Qt's signals and slots mechanism does not require classes to have knowledge of each other, which makes it much easier to develop highly reusable classes.

  1. Qt Signal Slot Const Reference Sheet
  2. Qt Signal Slot Const Reference Guide
  3. Qt Signal Slot Const Reference Example
  4. Qt Signal Slot Const Reference Generator


Remember old X-Window call-back system? Generally it isn't type safe and flexible. There are many problems with them. Qt offer new event-handling system - signal-slot connections. Imagine alarm clock. When alarm is ringing, signal is sending (emitting). And you're handling it as a slot.

  1. Every QObject class may have as many signals of slots as you want.
  2. You can emit signal only from that class, where signal is.
  3. You can connect signal with another signal (make chains of signals);
  4. Every signal and slot can have unlimited count of connections with other.
  5. ATTENTION! You can't set default value in slot attributes. e.g.void mySlot(int i = 0);


You can connect signal with this template:QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method);You have to wrap const char * signal and const char * method into SIGNAL () and SLOT() macros.

And you also can disconnect signal-slot:QObject::disconnect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method);


Widgets emit signals when events occur. For example, a button will emit a 'clicked' signal when it is clicked. A developer can choose to connect to a signal by creating a function (a 'slot') and calling the connect() function to relate the signal to the slot. Qt's signals and slots mechanism does not require classes to have knowledge of each other, which makes it much easier to develop highly reusable classes. Since signals and slots are type-safe, type errors are reported as warnings and do not cause crashes to occur.

For example, if a Quit button's clicked() signal is connected to the application's quit() slot, a user's click on Quit makes the application terminate. In code, this is written as

connect(button, SIGNAL (clicked()), qApp, SLOT (quit()));

Connections can be added or removed at any time during the execution of a Qt application, they can be set up so that they are executed when a signal is emitted or queued for later execution, and they can be made between objects in different threads.

The signals and slots mechanism is implemented in standard C++. The implementation uses the C++ preprocessor and moc, the Meta-Object Compiler, included with Qt. Code generation is performed automatically by Qt's build system. Developers never have to edit or even look at the generated code.

Retrieved from 'https://wiki.qt.io/index.php?title=Qt_signals_and_slots_for_newbies&oldid=28969'
Home · All Classes · Modules

The QCalendarWidget class provides a monthly based calendarwidget allowing the user to select a date. More..

Inherits QWidget.


  • enum HorizontalHeaderFormat { NoHorizontalHeader, SingleLetterDayNames, ShortDayNames, LongDayNames }
  • enum SelectionMode { NoSelection, SingleSelection }
  • enum VerticalHeaderFormat { NoVerticalHeader, ISOWeekNumbers }


  • int dateEditAcceptDelay (self)
  • dict-of-QDate-QTextCharFormat dateTextFormat (self)
  • bool event (self, QEvent event)
  • bool eventFilter (self, QObject watched, QEvent event)
  • QTextCharFormat headerTextFormat (self)
  • HorizontalHeaderFormat horizontalHeaderFormat (self)
  • bool isGridVisible (self)
  • bool isNavigationBarVisible (self)
  • QDate maximumDate (self)
  • QSize minimumSizeHint (self)
  • mousePressEvent (self, QMouseEvent event)
  • paintCell (self, QPainter painter, QRect rect, QDate date)
  • QDate selectedDate (self)
  • setCurrentPage (self, int year, int month)
  • setDateEditEnabled (self, bool enable)
  • setDateTextFormat (self, QDate date, QTextCharFormat color)
  • setGridVisible (self, bool show)
  • setHeaderTextFormat (self, QTextCharFormat format)
  • setHorizontalHeaderFormat (self, HorizontalHeaderFormat format)
  • setMinimumDate (self, QDate date)
  • setSelectedDate (self, QDate date)
  • setVerticalHeaderFormat (self, VerticalHeaderFormat format)
  • setWeekdayTextFormat (self, Qt.DayOfWeek dayOfWeek, QTextCharFormat format)
  • showNextYear (self)
  • showPreviousYear (self)
  • showToday (self)
  • updateCell (self, QDate date)
  • VerticalHeaderFormat verticalHeaderFormat (self)
  • QTextCharFormat weekdayTextFormat (self, Qt.DayOfWeek dayOfWeek)

Qt Signals

  • void activated (const QDate&)
  • void currentPageChanged (int,int)

Detailed Description

The QCalendarWidget class provides a monthly based calendarwidget allowing the user to select a date.

Qt Signal Slot Const Reference Sheet

The widget is initialized with the current month and year, butQCalendarWidget provides several public slots to change the yearand month that is shown.

Qt Signal Slot Const Reference Guide

By default, today's date is selected, and the user can select adate using both mouse and keyboard. The currently selected date canbe retrieved using the selectedDate()function. It is possible to constrain the user selection to a givendate range by setting the minimumDate andmaximumDateproperties. Alternatively, both properties can be set in one gousing the setDateRange() convenienceslot. Set the selectionModeproperty to NoSelection toprohibit the user from selecting at all. Note that a date also canbe selected programmatically using the setSelectedDate()slot.

The currently displayed month and year can be retrieved usingthe monthShown() andyearShown() functions,respectively. Sky ute casino resort ignacio colorado jobs.

A newly created calendar widget uses abbreviated day names, andboth Saturdays and Sundays are marked in red. The calendar grid isnot visible. The week numbers are displayed, and the first columnday is Sunday.

The notation of the days can be altered to a single letterabbreviations ('M' for 'Monday') by setting the horizontalHeaderFormatproperty to QCalendarWidget.SingleLetterDayNames.Setting the same property to QCalendarWidget.LongDayNamesmakes the header display the complete day names. The week numberscan be removed by setting the verticalHeaderFormatproperty to QCalendarWidget.NoVerticalHeader.The calendar grid can be turned on by setting the gridVisible property totrue using the setGridVisible()function:

Finally, the day in the first column can be altered using thesetFirstDayOfWeek()function.

The QCalendarWidget class also provides three signals, selectionChanged(),activated() andcurrentPageChanged()making it possible to respond to user interaction.

The rendering of the headers, weekdays or single days can belargely customized by setting QTextCharFormat's for some specialweekday, a special date or for the rendering of the headers.

Only a subset of the properties in QTextCharFormat are used by the calendarwidget. Currently, the foreground, background and font propertiesare used to determine the rendering of individual cells in thewidget.

Type Documentation


QCalendarWidget.SingleLetterDayNames1The header displays a single letterabbreviation for day names (e.g. M for Monday).
QCalendarWidget.ShortDayNames2The header displays a short abbreviation forday names (e.g. Mon for Monday).
QCalendarWidget.LongDayNames3The header displays complete day names (e.g.Monday).
QCalendarWidget.NoHorizontalHeader0The header is hidden.

See alsohorizontalHeaderFormat()and VerticalHeaderFormat.


QCalendarWidget.NoSelection0Dates cannot be selected.
QCalendarWidget.SingleSelection1Single dates can be selected.

See alsoselectionMode.

Qt Signal Slot Const Reference Example


QCalendarWidget.ISOWeekNumbers1The header displays ISO week numbers asdescribed by QDate.weekNumber().
QCalendarWidget.NoVerticalHeader0The header is hidden.

See alsoverticalHeaderFormat()and HorizontalHeaderFormat.

Method Documentation

QCalendarWidget.__init__ (self, QWidgetparent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a calendar widget with the given parent.

The widget is initialized with the current month and year, andthe currently selected date is today.

See alsosetCurrentPage().

int QCalendarWidget.dateEditAcceptDelay (self)

dict-of-QDate-QTextCharFormat QCalendarWidget.dateTextFormat (self)

Returns a QMap from QDate to QTextCharFormat showing all dates thatuse a special format that alters their rendering.

See alsosetDateTextFormat().

QTextCharFormat QCalendarWidget.dateTextFormat (self, QDatedate)

Returns a QTextCharFormat fordate. The char format can be be empty if the date is notrenderd specially.

bool QCalendarWidget.event (self, QEventevent)

Reimplemented from QObject.event().

bool QCalendarWidget.eventFilter (self, QObjectwatched, QEventevent)

Reimplemented from QObject.eventFilter().

Qt.DayOfWeek QCalendarWidget.firstDayOfWeek (self)

QTextCharFormat QCalendarWidget.headerTextFormat (self)

Returns the text char format for rendering the header.

See alsosetHeaderTextFormat().

Qt Signal Slot Const Reference Generator

HorizontalHeaderFormat QCalendarWidget.horizontalHeaderFormat (self)

bool QCalendarWidget.isDateEditEnabled (self)

bool QCalendarWidget.isGridVisible (self)

bool QCalendarWidget.isHeaderVisible (self)

bool QCalendarWidget.isNavigationBarVisible (self)

QCalendarWidget.keyPressEvent (self, QKeyEventevent)

Reimplemented from QWidget.keyPressEvent().

QDate QCalendarWidget.maximumDate (self)

QDate QCalendarWidget.minimumDate (self)

QSize QCalendarWidget.minimumSizeHint (self)

Reimplemented from QWidget.minimumSizeHint().

int QCalendarWidget.monthShown (self)

See alsoyearShown() and setCurrentPage().

QCalendarWidget.mousePressEvent (self, QMouseEventevent)

Reimplemented from QWidget.mousePressEvent().

QCalendarWidget.paintCell (self, QPainterpainter, QRectrect, QDatedate)

Paints the cell specified by the given date, using thegiven painter and rect.

QCalendarWidget.resizeEvent (self, QResizeEventevent)

Reimplemented from QWidget.resizeEvent().

QDate QCalendarWidget.selectedDate (self)

SelectionMode QCalendarWidget.selectionMode (self)

QCalendarWidget.setCurrentPage (self, int year, int month)

Displays the given month of the given year withoutchanging the selected date. Use the setSelectedDate()function to alter the selected date.

The currently displayed month and year can be retrieved usingthe monthShown() andyearShown() functionsrespectively.

See alsoyearShown(), monthShown(), showPreviousMonth(),showNextMonth(),showPreviousYear(), andshowNextYear().

QCalendarWidget.setDateEditAcceptDelay (self, int delay)

QCalendarWidget.setDateEditEnabled (self, bool enable)

QCalendarWidget.setDateRange (self, QDatemin, QDatemax)

This method is also a Qt slot with the C++ signature void setDateRange(const QDate&,const QDate&).

Defines a date range by setting the minimumDate andmaximumDateproperties.

The date range restricts the user selection, i.e. the user canonly select dates within the specified date range. Note that

is analogous to

If either the min or max parameters are not validQDate objects, this function doesnothing.

See alsosetMinimumDate() andsetMaximumDate().

QCalendarWidget.setDateTextFormat (self, QDatedate, QTextCharFormatcolor)

Sets the format used to render the given date to thatspecified by format.

If date is null, all date formats are cleared.

See alsodateTextFormat().

QCalendarWidget.setFirstDayOfWeek (self, Qt.DayOfWeekdayOfWeek)

QCalendarWidget.setGridVisible (self, bool show)

QCalendarWidget.setHeaderTextFormat (self, QTextCharFormatformat)

Sets the text char format for rendering the header toformat. If you also set a weekday text format, this format'sforeground and background color will take precedence over theheader's format. The other formatting information will still bedecided by the header's format.

Qt signal slot const reference example

See alsoheaderTextFormat().

QCalendarWidget.setHeaderVisible (self, bool show)

QCalendarWidget.setHorizontalHeaderFormat (self, HorizontalHeaderFormatformat)

QCalendarWidget.setMaximumDate (self, QDatedate)

QCalendarWidget.setMinimumDate (self, QDatedate)

QCalendarWidget.setNavigationBarVisible (self, bool visible)

QCalendarWidget.setSelectedDate (self, QDatedate)

This method is also a Qt slot with the C++ signature void setSelectedDate(const QDate&).

QCalendarWidget.setSelectionMode (self, SelectionModemode)

QCalendarWidget.setVerticalHeaderFormat (self, VerticalHeaderFormatformat)

QCalendarWidget.setWeekdayTextFormat (self, Qt.DayOfWeekdayOfWeek, QTextCharFormatformat)

Sets the text char format for rendering of day in the weekdayOfWeek to format. The format will take precedenceover the header format in case of foreground and background color.Other text formatting information is taken from the headersformat.

See alsoweekdayTextFormat()and setHeaderTextFormat().


QCalendarWidget.showNextMonth (self)

See alsoshowPreviousMonth(),setCurrentPage(),and setSelectedDate().

QCalendarWidget.showNextYear (self)

See alsoshowPreviousYear(),setCurrentPage(),and setSelectedDate().

QCalendarWidget.showPreviousMonth (self)

See alsoshowNextMonth(), setCurrentPage(), andsetSelectedDate().

QCalendarWidget.showPreviousYear (self)

See alsoshowNextYear(), setCurrentPage(), andsetSelectedDate().

QCalendarWidget.showSelectedDate (self)

See alsoselectedDate() andsetCurrentPage().

QCalendarWidget.showToday (self)

See alsoselectedDate() andsetCurrentPage().

QSize QCalendarWidget.sizeHint (self)

Reimplemented from QWidget.sizeHint().

QCalendarWidget.updateCell (self, QDatedate)

Updates the cell specified by the given date unlessupdates are disabled or the cell is hidden.

This function was introduced in Qt 4.4.

See alsoupdateCells(), yearShown(), and monthShown().

QCalendarWidget.updateCells (self)

See alsoupdateCell().

VerticalHeaderFormat QCalendarWidget.verticalHeaderFormat (self)

QTextCharFormat QCalendarWidget.weekdayTextFormat (self, Qt.DayOfWeekdayOfWeek)

Returns the text char format for rendering of day in the weekdayOfWeek.

See alsosetWeekdayTextFormat()and headerTextFormat().

int QCalendarWidget.yearShown (self)

See alsomonthShown() and setCurrentPage().

Qt Signal Documentation

void activated (const QDate&)

void clicked (const QDate&)

This signal is emitted when a mouse button is clicked. The datethe mouse was clicked on is specified by date. The signal isonly emitted when clicked on a valid date, e.g., dates are notoutside the minimumDate() andmaximumDate().If the selection mode is NoSelection, thissignal will not be emitted.

void currentPageChanged (int,int)

See alsosetCurrentPage().

void selectionChanged ()

The currently selected date can be changed by the user using themouse or keyboard, or by the programmer using setSelectedDate().

See alsoselectedDate().

PyQt 4.11.4 for X11Copyright © Riverbank Computing Ltd and The Qt Company 2015Qt 4.8.7