I have noticed that there is a bug in QDateEdit widget, I am using Qt Designer 5.15.2 to design QPushButton, QDateEdit and QLineEdit with python 3.9.2:
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
import sys
Ui_MainWindow,_ = loadUiType('tst.ui')
def __init__(self):
self.setupUi(self)
self.btn.clicked.connect(self.enterDATE) #QPushButton signal
def enterDATE(self):
Date_2021_03_26 = "{0}-{1}-{2}".format(self.deDateEdit.date().year(), self.deDateEdit.date().month(), self.deDateEdit.date().day()) #QDateEdit
self.LineEdit.setText(Date_2021_03_26) #QLineEdit
def main():
win = TEST()
win.show()
app.exec_()
if __name__ == '__main__':
main()
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
import sys
Ui_MainWindow,_ = loadUiType('tst.ui')
class TEST(Ui_MainWindow, QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.btn.clicked.connect(self.enterDATE) #QPushButton signal
def enterDATE(self):
Date_2021_03_26 = "{0}-{1}-{2}".format(self.deDateEdit.date().year(), self.deDateEdit.date().month(), self.deDateEdit.date().day()) #QDateEdit
self.LineEdit.setText(Date_2021_03_26) #QLineEdit
def main():
app = QApplication(sys.argv)
win = TEST()
win.show()
app.exec_()
if __name__ == '__main__':
main()
To copy to clipboard, switch view to plain text mode
you will notice that when you try to type this specific date: 2021-03-26 by keyboard, it will be rejected (in my case it sat to 2021-03-01)
if you try other dates (try change the year, month and day) it will accept them. why this happened only for this date 2021-03-26?
note that: if you use the updown arrows to type(select) the date, it will accept the date 2021-03-26
I hope someone help me to understand the reason.
Bookmarks