Created
March 15, 2022 12:44
-
-
Save l-arkadiy-l/41c474b5f65c58b97ce5543d484ee9e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtCore import * | |
from PyQt5.QtWidgets import * | |
from PyQt5.QtGui import * | |
class WeekCalendar(QCalendarWidget): | |
def __init__(self, *args): | |
QCalendarWidget.__init__(self, *args) | |
self.color = QColor(255, 245, 8) | |
self.color.setAlpha(64) | |
self.selectionChanged.connect(self.updateCells) | |
def paintCell(self, painter, rect, date): | |
QCalendarWidget.paintCell(self, painter, rect, date) | |
first_day = self.firstDayOfWeek() | |
last_day = first_day + 6 | |
current_date = self.selectedDate() | |
current_day = current_date.dayOfWeek() | |
if first_day <= current_day: | |
first_date = current_date.addDays(first_day - current_day) | |
else: | |
first_date = current_date.addDays(first_day - 7 - current_day) | |
last_date = first_date.addDays(6) | |
if first_date <= date <= last_date: | |
painter.fillRect(rect, self.color) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
web = WeekCalendar() | |
web.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment