Всем привет, у меня такой вопрос...
У меня дан список дат, к примеру
['2022-10-05', '2022-10-13', '2022-10-14', '2022-10-15']
Как мне их закрасить в календаре?
from PyQt5.QtWidgets import QWidget, QApplication, QListWidgetItem, QMessageBox, QCalendarWidget
from PyQt5.uic import loadUi
from PyQt5 import QtCore
import sys
import tmp
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
loadUi("main.ui", self)
self.calendarWidget.selectionChanged.connect(self.calendar_date_changed)
self.calendar_date_changed()
self.saveButton.clicked.connect(self.save_changes)
self.addButton.clicked.connect(self.add_new_task)
def calendar_date_changed(self):
dateSelected = self.calendarWidget.selectedDate().toPyDate()
self.update_task_list(dateSelected)
def update_task_list(self, date):
self.tasksListWidget.clear()
user_id = 0
if (str(user_id) in tmp.read()["data"]["tasks"].keys()) and (str(date) in tmp.read()["data"]["tasks"][str(user_id)].keys()):
results = tmp.read()["data"]["tasks"][str(user_id)][str(date)]
for key in results.keys():
item = QListWidgetItem(key)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
if results[key] is True:
item.setCheckState(QtCore.Qt.Checked)
elif results[key] is False:
item.setCheckState(QtCore.Qt.Unchecked)
self.tasksListWidget.addItem(item)
def add_new_task(self):
user_id = 0
task = str(self.taskLineEdit.text())
date = self.calendarWidget.selectedDate().toPyDate()
stat = False
tmp.add_task(user_id, date, task, stat)
self.update_task_list(date)
self.taskLineEdit.clear()
def save_changes(self):
user_id = 0
date = self.calendarWidget.selectedDate().toPyDate()
for i in range(self.tasksListWidget.count()):
item = self.tasksListWidget.item(i)
task = item.text()
if item.checkState() == QtCore.Qt.Checked:
tmp.edit_task_status(str(user_id), date, task, True)
else:
tmp.edit_task_status(str(user_id), date, task, False)
messageBox = QMessageBox()
messageBox.setText("Changes saved.")
messageBox.setStandardButtons(QMessageBox.Ok)
messageBox.exec()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())