📜  PyQt5 QDateEdit – 完成信号

📅  最后修改于: 2022-05-13 01:55:22.737000             🧑  作者: Mango

PyQt5 QDateEdit – 完成信号

在本文中,我们将了解如何获得 QDateEdit 的完成信号。发出此信号,编辑完成。当日期编辑失去焦点并且按下回车键时,会发生这种情况。该信号非常重要,因为它仅在编辑完成时才发生,不像其他信号在小时间间隔内获得很多时间。

为了做到这一点,我们使用带有 QDateEdit 对象的editingFinished方法

下面是实现

# 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, 500, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for components
    def UiComponents(self):
          
        # creating a QDateEdit widget
        date = QDateEdit(self)
  
        # setting geometry of the date edit
        date.setGeometry(100, 100, 150, 40)
  
        # creating a label
        label = QLabel("GeeksforGeeks", self)
  
        # setting geometry
        label.setGeometry(100, 150, 200, 60)
  
        # making label multiline
        label.setWordWrap(True)
  
        # getting finished signal
        date.editingFinished.connect(lambda: date_method())
  
        # method called by date edit
        def date_method():
  
            # setting text to the label
            label.setText("Finished Signal Emitted")
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :