问题
I built simple widget in Qt Designer with a button and a QDateEdit. The user will enter the date into the QDateEdit and then when he presses the button, the date will be saved to a variable.
How can I do it?
回答1:
You can make it simply:
var_name = self.dateEdit.date()
This will get you a variable in QDate format. If you need it in a format which would be easier to work with then you should use this:
temp_var = self.dateEdit.date()
var_name = temp_var.toPyDate()
The first one gives you: "PyQt4.QtCore.QDate(2011, 11, 8)"
While the second returns: "2011-11-08"
来源:https://stackoverflow.com/questions/8049055/pyqt-get-date-from-the-user