PyQt5 QCalendarWidget – Clearing Focus
Last Updated :
18 Feb, 2022
In this article we will see how we can clear the focus of the QCalendarWidget if it has focus. Setting focus is basically setting focus reason there are many focus reason available like backtab, popup reason etc. Setting focus is the overloaded function. We use setFocus method to set focus to the calendar.
In order to do this we will use clearFocus method with the QCalendarWidget object.
Syntax : calendar.childFocus()
Argument : It takes no argument
Return : It return None
Below is the implementation
Python3
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__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 650 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
self .calendar = QCalendarWidget( self )
self .calendar.setGeometry( 50 , 10 , 400 , 250 )
self .calendar.setFocus(Qt.NoFocusReason)
self .calendar.clearFocus()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...