简体   繁体   中英

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:

在此处输入图片说明

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)

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM