summaryrefslogtreecommitdiff
path: root/tropical/qt/caldrawer.py
diff options
context:
space:
mode:
authorLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 20:31:06 +0200
committerLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 20:31:06 +0200
commit3c44a536a7259cc46aa42a7b847c8c9636bd2aa0 (patch)
tree4f45b6b6e381cefe5ae7ba41842e8824dd1fb84b /tropical/qt/caldrawer.py
parentbbfdc515fb2296e78b3c8c8e4f0a501bf7aa007d (diff)
Minor changes
Diffstat (limited to 'tropical/qt/caldrawer.py')
-rw-r--r--tropical/qt/caldrawer.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tropical/qt/caldrawer.py b/tropical/qt/caldrawer.py
index 7e6b3fc..20eaf14 100644
--- a/tropical/qt/caldrawer.py
+++ b/tropical/qt/caldrawer.py
@@ -12,7 +12,8 @@ class CalQGraphicsView(QGraphicsView):
def __init__(self, scene):
super().__init__(None)
self.setScene(scene)
-
+ self.setMouseTracking(True) # Allow to keep track of mouse location in the scene
+
def resizeEvent(self, event):
self.fitInView(self.sceneRect(), Qt.AspectRatioMode.IgnoreAspectRatio)
@@ -26,9 +27,11 @@ class CalDrawerScene(QGraphicsScene):
self.showWeekends=True
self.daysRect=list()
self.eventsRect=list()
+ self.mouseOver=-1
self.calState=calState
self.daysNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
+
def drawForeground(self, painter, rect):
origXF, origYF, widthF, heightF = rect.getRect()
origXI, origYI, widthI, heightI = (int(origXF),int(origYF),int(widthF),int(heightF))
@@ -75,6 +78,9 @@ class CalDrawerScene(QGraphicsScene):
po=int(self.gridWidth/2) # Pen offset
painter.setPen(pen)
# Init Brush
+ brushHL=QtGui.QBrush()
+ brushHL.setColor(QtGui.QColor("#e5e5e5"))
+ brushHL.setStyle(Qt.BrushStyle.SolidPattern)
painter.setBrush(Qt.BrushStyle.NoBrush)
# Setup dimensions
weekLength=7
@@ -103,7 +109,12 @@ class CalDrawerScene(QGraphicsScene):
# painter.drawRect(QRect(b.x(),b.y(),b.width(),b.height()))
# painter.setPen(self.gridPen)
# painter.setBrush(self.defaultBrush)
- painter.drawRect(rect)
+ if row*weekLength+col == self.mouseOver:
+ painter.setBrush(brushHL)
+ painter.drawRect(rect)
+ painter.setBrush(Qt.BrushStyle.NoBrush)
+ else:
+ painter.drawRect(rect)
col+=1
if col==weekLength:
col=0
@@ -170,6 +181,20 @@ class CalDrawerScene(QGraphicsScene):
painter.drawRect(r.x(),r.y(),colMark,labelH) # Remember r is within grid stroke
painter.setPen(pen)
+ def mouseMoveEvent(self, event):
+ """
+ This is possible because of self.setMouseTracking(True) inside the view
+ """
+ pos=event.scenePos()
+ x, y=(int(pos.x()),int(pos.y()))
+ self.mouseOver=-1
+ for i in range(0,len(self.daysRect)):
+ r=self.daysRect[i]
+ if r.contains(x,y):
+ self.mouseOver=i
+ self.update()
+ break
+
class CalDrawer():
def __init__(self, layout, calState):