Open In App

PyQt5 QCalendarWidget – Getting horizontal header format

Last Updated : 06 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

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  

Python3




# 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):
        super().__init__()
 
        # setting title
        self.setWindowTitle("Python ")
 
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
 
        # calling method
        self.UiComponents()
 
        # showing all the widgets
        self.show()
 
    # 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
        calendar.setHorizontalHeaderFormat(QCalendarWidget.LongDayNames)
 
        # creating a label
        label = QLabel(self)
 
        # setting geometry to the label
        label.setGeometry(100, 300, 250, 60)
 
        # making label multi line
        label.setWordWrap(True)
 
        # 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
sys.exit(App.exec())


Output : 

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads