summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 22:40:20 +0200
committerLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 22:40:20 +0200
commit277ed8637d3f718c7d3e55fb978fe14bd378e294 (patch)
tree54d1c691144b78a4f248604c134c482b9b0340f2
parent3c44a536a7259cc46aa42a7b847c8c9636bd2aa0 (diff)
Minor changes
-rw-r--r--tropical/qt/caldrawer.py22
-rw-r--r--tropical/qt/mainwindow.py10
2 files changed, 25 insertions, 7 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);
diff --git a/tropical/qt/mainwindow.py b/tropical/qt/mainwindow.py
index 7089b24..4056bca 100644
--- a/tropical/qt/mainwindow.py
+++ b/tropical/qt/mainwindow.py
@@ -4,7 +4,7 @@
from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow
from PyQt6 import uic, QtGui
from PyQt6.QtCore import Qt
-from .caldrawer import CalDrawer
+from .caldrawer import *
from .eventdrawer import EvtDrawer
from .createcalendar import CreateCalendar
@@ -17,13 +17,19 @@ class MainWindow(QMainWindow):
def __init__(self,uipath, calState):
super(MainWindow,self).__init__()
uic.loadUi(uipath+"/MainWindow.ui",self)
- self.calDrawer=CalDrawer(self.calContainer.layout(),calState)
+ self.calDrawer=CalDrawer(self, self.calContainer.layout(),calState)
self.evtDrawer=EvtDrawer(self.calContainer.layout(),calState)
self.calState=calState
self.show()
def setVersion(self,version):
self.statusbar.showMessage("Calanus v"+version,0)
+
+ def event(self, event):
+ if event.type() == DaySelectedEvent:
+ print("Ho")
+ return QWidget.event(self,event) #super().event(event)
+
def StartApplication(version,calState):
path = os.path.dirname(os.path.abspath(__file__))+"/designer"