I am trying to write a simple code where a user picks a date, and the seleced date is displayed using the Qlabel function. However, I am making a mistake in transmitting the signal and wanted to ask if someone could help me with my code. Thank you.
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.dateEdit = QtGui.QDateEdit(self)
self.lbl = QtGui.QLabel()
self.dateEdit.setDateTime(QtCore.QDateTime.currentDateTime())
self.dateEdit.setMaximumDate(QtCore.QDate(7999, 12, 28))
self.dateEdit.setMaximumTime(QtCore.QTime(23, 59, 59))
self.dateEdit.setCalendarPopup(True)
layout = QGridLayout()
layout.addWidget(self.dateEdit,0,0)
layout.addWidget(self.lbl,0,1)
self.setLayout(layout)
self.connect(self.dateEdit, SIGNAL("dateChanged()"), self.updateUi)
def updateUi(self):
date1 = self.QtGui.QDateTimeEdit.QDate.date(self)
self.lbl.setText(date1.toString())
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('MyWindow')
main = MyWindow()
main.show()
sys.exit(app.exec_())