Results 1 to 3 of 3

Thread: QDateEdit bug

  1. #1
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QDateEdit bug

    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:
    Qt Code:
    1. from PyQt5.QtWidgets import *
    2. from PyQt5.uic import loadUiType
    3. import sys
    4. Ui_MainWindow,_ = loadUiType('tst.ui')
    5. class TEST(Ui_MainWindow, QMainWindow):
    6. def __init__(self):
    7. QMainWindow.__init__(self)
    8. self.setupUi(self)
    9. self.btn.clicked.connect(self.enterDATE) #QPushButton signal
    10. def enterDATE(self):
    11. Date_2021_03_26 = "{0}-{1}-{2}".format(self.deDateEdit.date().year(), self.deDateEdit.date().month(), self.deDateEdit.date().day()) #QDateEdit
    12. self.LineEdit.setText(Date_2021_03_26) #QLineEdit
    13. def main():
    14. app = QApplication(sys.argv)
    15. win = TEST()
    16. win.show()
    17. app.exec_()
    18. if __name__ == '__main__':
    19. 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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,722
    Thanks
    13
    Thanked 1,605 Times in 1,532 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDateEdit bug

    No issue here with Qt 5.12 and Python 3.8.5. Break for you?
    Qt Code:
    1. from PyQt5.QtWidgets import *
    2. from PyQt5.QtCore import QDate
    3. import sys
    4.  
    5. class Widget(QWidget):
    6. def __init__(self):
    7. QWidget.__init__(self)
    8. self.dateEdit = QDateEdit()
    9. self.dateEdit.setDate(QDate(2021, 3, 1))
    10. self.dateEdit.setDisplayFormat("yyyy-MM-dd")
    11. self.lineEdit = QLineEdit(self)
    12. layout = QVBoxLayout(self)
    13. layout.addWidget(self.dateEdit)
    14. layout.addWidget(self.lineEdit)
    15. self.dateEdit.setFocus()
    16. self.dateEdit.dateChanged.connect(self.showDate)
    17.  
    18. def showDate(self, date):
    19. dateString = "{0}-{1}-{2}".format(date.year(), date.month(), date.day())
    20. self.lineEdit.setText(dateString)
    21.  
    22. def main():
    23. app = QApplication(sys.argv)
    24. win = Widget()
    25. win.show()
    26. app.exec_()
    27.  
    28. if __name__ == '__main__':
    29. main()
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDateEdit bug

    my friend,, I tried your code.
    if you changed self.dateEdit.setDate(QDate(2021, 3, 1)) to self.dateEdit.setDate(QDate(2021, 1, 1))
    and tried to type 2021-03-26 , you will get a problem (bug)
    I can't set date to 2021-03-01, because when you design an application, you will set the date to the default which is year/01/01 .

Similar Threads

  1. Replies: 3
    Last Post: 24th January 2017, 09:13
  2. QDateEdit clear()
    By Henry Blue Heeler in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2014, 23:24
  3. 2 QDateEdit with 1 QCalendarWidget ?
    By ouekah in forum Newbie
    Replies: 4
    Last Post: 26th April 2010, 09:24
  4. Null for QDateEdit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2009, 21:54
  5. Subclassing QDateEdit
    By jamadagni in forum Qt Programming
    Replies: 6
    Last Post: 4th February 2006, 13:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.