PyQt5 QCalendarWidget – 获取日期编辑(弹出)接受延迟
在本文中,我们将了解如何获取 QCalendarWidget 的日期编辑接受延迟属性。此属性保存在接受其内容之前显示非活动日期编辑的时间。如果启用了日历小部件的日期编辑,则此属性指定在最近的用户输入之后日期编辑保持打开状态的时间量(以毫秒为单位)。这段时间过去后,日期编辑中指定的日期将被接受并关闭弹出窗口。默认情况下,延迟定义为 1500 毫秒(1.5 秒)。
当我们尝试使用键盘选择时,会出现日期编辑弹出窗口,延迟弹出的值越小,关闭的速度就越快。可以借助 setDateEditAcceptDelay 方法进行设置。
In order to do this we will use dateEditAcceptDelay method with the QCalendarWidget object.
Syntax : calendar.dateEditAcceptDelay()
Argument : It takes no argument
Return : It return integer
下面是实现
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, 650, 400)
# calling method
self.UiComponents()
# showing all the widgets
self.show()
# method for components
def UiComponents(self):
# creating a QCalendarWidget object
self.calendar = QCalendarWidget(self)
# setting geometry to the calendar
self.calendar.setGeometry(50, 10, 400, 250)
# setting cursor
self.calendar.setCursor(Qt.PointingHandCursor)
# removing special cursor
self.calendar.unsetCursor()
# setting accept delay value
self.calendar.setDateEditAcceptDelay(2000)
# creating a label
label = QLabel(self)
# setting geometry
label.setGeometry(50, 280, 420, 120)
# making it multi line
label.setWordWrap(True)
# getting delay time in pop-up
value = self.calendar.dateEditAcceptDelay()
# setting text to the label
label.setText("Accept Delay : " + str(value))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :