Skip to content
Related Articles

Related Articles

Improve Article

PyQt5 QCalendarWidget – Getting horizontal header format

  • Last Updated : 06 Aug, 2021

In this article, we will see how we can get the horizontal header format of the QCalendarWidget. Horizontal header is the place in QCalendarWidget which shows the days name by default short form of days are show, for example, Monday is displayed as Mon. By default, ShortDayNames is the format of the horizontal header although we can change this with the help of setHorizontalHeaderFormat method.

There are many formats available for the horizontal header like SingleLetterDayNames, its value is 1 and this format displays only the first letter of the days name, ShortDayNames, it is the default format, its value is 2 and this format displays only the short form of the days name. And LongDayNames its value is 3 and this format displays whole name of the days.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

In order to do this we use horizontalHeaderFormat method with the QCalendarWidget object
Syntax : calendar.horizontalHeaderFormat()
Argument : It takes no argument
Return : It returns Horizontal Header format object but when printed it shows associated value with them 

Below is the implementation  


# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # calling method
        # showing all the widgets
    # method for components
    def UiComponents(self):
        # creating a QCalendarWidget object
        calendar = QCalendarWidget(self)
        # setting geometry to the calendar
        calendar.setGeometry(10, 10, 400, 250)
        # setting calendar horizontal header format
        # creating a label
        label = QLabel(self)
        # setting geometry to the label
        label.setGeometry(100, 300, 250, 60)
        # making label multi line
        # getting the horizontal header format
        value = calendar.horizontalHeaderFormat()
        # setting text to the label
        label.setText("Horizontal Header format value : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output : 


My Personal Notes arrow_drop_up
Recommended Articles
Page :