summaryrefslogtreecommitdiff
path: root/tropical/qt/caldrawer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tropical/qt/caldrawer.py')
-rw-r--r--tropical/qt/caldrawer.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/tropical/qt/caldrawer.py b/tropical/qt/caldrawer.py
index 20eaf14..39f72a1 100644
--- a/tropical/qt/caldrawer.py
+++ b/tropical/qt/caldrawer.py
@@ -1,13 +1,15 @@
from PyQt6.QtWidgets import QGraphicsScene, QGraphicsView, QSizePolicy
from PyQt6 import uic, QtGui, QtCore
-from PyQt6.QtCore import Qt, QRect
+from PyQt6.QtCore import Qt, QRect, QEvent, QCoreApplication
import math
#https://forum.qt.io/topic/93327/how-can-i-use-qpainter-to-paint-on-qgraphicsview/5
#https://www.pythonguis.com/tutorials/pyqt6-bitmap-graphics/#qpainter
# to solve the fit problem: https://stackoverflow.com/questions/61886358/qgraphicsview-fitinview-not-working-as-expected
+DaySelectedEvent = QEvent.registerEventType()
+
class CalQGraphicsView(QGraphicsView):
def __init__(self, scene):
super().__init__(None)
@@ -19,7 +21,8 @@ class CalQGraphicsView(QGraphicsView):
class CalDrawerScene(QGraphicsScene):
- def __init__(self, calState):
+ def __init__(self, parent, calState):
+ self.parent=parent
self.gridWidth=2
self.daysLabelBG="#dddddd"
self.eventsLabelBG="#36e364"
@@ -193,12 +196,21 @@ class CalDrawerScene(QGraphicsScene):
if r.contains(x,y):
self.mouseOver=i
self.update()
+ event.accept()
break
-
+
+ def mousePressEvent(self, event):
+ b=event.button()
+ if self.mouseOver>=0 and b==Qt.MouseButton.LeftButton:
+ event.accept()
+ event = QEvent(DaySelectedEvent)
+ QCoreApplication.postEvent(self.parent, event)
+
+
class CalDrawer():
- def __init__(self, layout, calState):
- self.gs=CalDrawerScene(calState)
+ def __init__(self, parent, layout, calState):
+ self.gs=CalDrawerScene(parent, calState)
self.gv=CalQGraphicsView(self.gs)
# Setup propertion
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);