-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar_widget.py
46 lines (36 loc) · 1.54 KB
/
calendar_widget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QEvent, QObject
from PyQt5.QtWidgets import *
from stylesheets import *
class CalendarWidget(QtWidgets.QWidget):
tooltip = None
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def __init__(self, window, date, task_count):
super().__init__()
self.window = window
self.date = date
self.task_count = task_count
width = 10
self.setFixedWidth(width)
self.setFixedHeight(width)
self.widget = QWidget(self)
self.widget.setFixedWidth(width)
self.widget.setFixedHeight(width)
self.installEventFilter(self)
def eventFilter(self, a0: 'QObject', a1: 'QEvent') -> bool:
if a1.type() == QEvent.Enter:
self.create_tooltip(a0, a1)
return super().eventFilter(a0, a1)
def leaveEvent(self, a0: QtCore.QEvent) -> None:
self.tooltip.deleteLater()
return super().leaveEvent(a0)
def create_tooltip(self, a0, a1):
weekday = self.weekdays[self.date.weekday()]
task_text = "Task" if self.task_count == 1 else "Tasks"
text = "{}, {} \n{} {}".format(weekday, self.date, self.task_count, task_text)
tooltip = QLabel(text, self.window.ui.centralwidget)
tooltip.move(self.pos()+QtCore.QPoint(120, 100))
tooltip.setStyleSheet(calendar_tooltip_style)
tooltip.adjustSize()
tooltip.show()
self.tooltip = tooltip