pythonpyqt4qdate

Setting a minimum QDate with todays date


I'm trying to set the minimum date for a QDate box to todays date. I keep getting a syntax. I have set the format which works fine, but the minimum date won't work.

    self.ui.CreateStuDOB.setDisplayFormat("dd.MM.yyyy")
    self.ui.CreateStuDOB.setMinimumDate(QDate::currentDate())

Returned error

self.ui.CreateStuDOB.setMinimumDate(QDate::currentDate()) ^ SyntaxError: invalid syntax

Thanks in advance


Solution

  • Solved.

    Firstly I used the correct Python syntax instead of the C++ syntax as pointed out by ekhumoro.

    self.ui.CreateStuDOB.setMinimumDate(QDate.currentDate())
    

    Then I correctly imported QDate using:

    from PyQt4.QtCore import *