QDateEntry: setting current date as mimimum

Rich Shepard rshepard at appl-ecosys.com
Wed May 5 18:46:30 BST 2021


Looking for the proper way to set the current date as the minimum for a
QDateEntry widget python shows an error at the beginning of that line and,
despite my looking at examples on web pages, I don't see my error.

The error:
$ python mwe.py
   File "mwe.py", line 18
     cont_date.setMinimumDate(QDate(self.now_date)),
     ^
SyntaxError: positional argument follows keyword argument

I don't know which are the positional and keyword errors because there are
so many constraints set on this widget.

Looking forward to learning,

Rich
-------------- next part --------------
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc

class MWEWindow(qtw.QWidget):
    def __init__(self):
        super().__init__()
        wintitle = qtw.QWidget(windowTitle='Minimum Working Example')
        self.setGeometry(300, 200, 800, 600)

        # Widgets
        cont_date_lbl = qtw.QLable('Date', self)
        cont_date = qtw.QDateEntry(self,
            date = qtc.QDate.currentDate(),
            calendarPopup = True,
            displayFormat = 'yyyy-MM-dd HH:mm',
            cont_date.setMinimumDate(QDate(self.now_date)),
            cont_date.setSizePolicy(qtw.QSizePolicy.Fixed,                                                          qtw.QSizePolicy.Preferred))

        # button_row
        savebutton = qtw.QPushButton('Save')
        savebutton.clicked.connect(self.save)
        cancelbutton = qtw.QPushButton('Cancel')
        cancelbutton.clicked.connect(self.cancel)

        # Layouts used for widgets
        # Row 1
        row1 = QHBoxLayout()
        row1.addWidget(cont_date_lbl)
        row1.addWidget(cont_date)
        butrow = QHBoxlayout()
        butrow.addWidget(savebutton)
        butrow.addWidget(cancelbutton)

        # Main window layout
        inner = qtw.QVBoxLayout()
        inner.addLayout(row1)
        inner.addLayout(butrow)
        outer = qtw.QWidget(self)
        outer.setLayout(inner)

        self.show()


if __name__ == '__main__':
    app = qtw.QApplication(sys.argv)
    mwe = MWEWindow()
    sys.exit(app.exec())


More information about the PyQt mailing list