[PyQt] QDateEdit keeps me strictly in current month

Sibylle Koczian Sibylle.Koczian at t-online.de
Wed Jan 2 17:23:39 GMT 2008


to my inexperienced eyes this looks like a bug: a QDateEdit should let me 
choose any day in the last month, but I can't get to dates this past 
December. Direct editing doesn't work, using the arrow for earlier dates 
doesn't work. 

If I change the date range to November 2, 2007 until December 2, 2007, I can 
reach every day if I change first the month and then the day. This isn't very 
intuitive using my normal date format (day.month.year), but at least it 
works. For December 2, 2007 to January 2, 2008 I didn't find any workaround.

My suspicion: this happens, because the date has to stay valid all through the 
editing process, and this isn't always possible.

Here is my test application. Changing between 
lastdate = today 
lastdate = today.addMonths(-1) (commented out)
should demonstrate the problem.

# test_dateedit_dlg.py
# QDateEdit testen

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class TestDateDlg(QDialog):

    def __init__(self, parent=None):
        super(TestDateDlg, self).__init__(parent)
        today = QDate.currentDate()
        lastdate = today
#        lastdate = today.addMonths(-1)
        firstdate = today.addMonths(-2)
        self.edDate = QDateEdit()
        self.edDate.setDateRange(firstdate, lastdate)
        self.datelist = QListWidget()
        self.datelist.addItem(QString('Starting date: %1')\
        self.datelist.addItem(QString('Current date: %1')\
        layout = QVBoxLayout()
        self.connect(self.edDate, SIGNAL('editingFinished()'), self.logDate)

    def logDate(self):
        newdate = self.edDate.date().toString(Qt.ISODate)
        self.datelist.addItem(QString('New date: %1').arg(newdate))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = TestDateDlg()

Dr. Sibylle Koczian

More information about the PyQt mailing list