pythonqtpyqtqdate

QDateEdit - paint cell of calendarPopup


I create custom form and user interface components with Qt Designer and use Qt's integrated build tool uic, to generate code for them when the application is built. The generated code contains the form's user interface object.

I have QDockWidget with QDateEdit, I want to paint cells of some date:

enter image description here

I want to do something like this:

    date_to = self.dockwidget.findChild(QDateEdit, "date_to")
    painter = QPainter()
    painter.fillRect(QRect(25, 25, 25, 25), Qt.red)
    date_to.calendarWidget().paintCell(painter, QRect(25, 25, 25, 25), QDate(2018, 8, 2))

How to use paintCell in this case

Virtual function:

def paintCell (painter, rect, date)


Solution

  • here is solution if someone else will need it:

    QCalendarWidget.setDateTextFormat(QDate, QTextCharFormat)

        format = QTextCharFormat()
        format.setBackground(Qt.yellow)
        date_to = self.dockwidget.findChild(QDateEdit, "date_to")
        date_to.calendarWidget().setDateTextFormat(QDate(2019, 2, 2),format)
    

    Result:

    enter image description here