Всем привет. Я хочу добавить к моему календарю метки на даты, которые у меня имеются в переменной.
Полагаю, необходимо передать date_list (переменную с датами) с родительского класса в этот метод и отметить все даты на календаре.
Нашел на форуме схожий вопрос Как изменить фон определённой ячейки в QCalendarWidget?.
Я хочу сделать так же, но только чтобы вместо списка 0 и 1 сразу подавался список дат (т.к. даты могут и добавляться и удаляться с этой переменной) + сохранить окрашивание сегодняшней даты, что я уже написал в paintCell.
Вот код моего CustomCalendar.py:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QDate, QPoint, Qt
class MyCalendar(QtWidgets.QCalendarWidget):
def __init__(self, parent=None):
QtWidgets.QCalendarWidget.__init__(self, parent)
def paintCell(self, painter, rect, date):
QtWidgets.QCalendarWidget.paintCell(self, painter, rect, date)
if date == date.currentDate():
painter.setBrush(QtGui.QColor(122, 27, 181, 50))
painter.setPen(QtGui.QColor(0, 0, 0, 0))
painter.drawRect(rect)
painter.setPen(QtGui.QPen(QtGui.QColor(110, 20, 160), 1, Qt.SolidLine, Qt.RoundCap))
painter.drawLine(rect.topRight(), rect.topLeft())
painter.drawLine(rect.topRight(), rect.bottomRight())
painter.drawLine(rect.bottomLeft(), rect.bottomRight())
painter.drawLine(rect.topLeft(), rect.bottomLeft())