wandererfan wrote: ↑Fri Dec 02, 2022 2:30 pm
QGraphicsScene (Mod/TechDraw/Gui.QGSPage.cpp) and QGraphicsItem (QGXXXX.cpp) have methods for MouseButtonPress, MouseMove, etc. The way to get access to the events is to derive a new class that overrides those methods.
Can you provide a working example in Python?
May try it based on the code from the repository... It's been cleaned.
https://github.com/FreeCAD-Tools/FreeCA ... /tree/main
wandererfan wrote: ↑Fri Dec 02, 2022 2:30 pm
The full stack would be something like:
App/WiringSymbol - a document object to hold your svg and any other parameters you need
Gui/QGWiringSymbol - a QGraphicsItem that paints the symbol and handles events in the item's bounding rect.
Gui/ViewProvider - (a ViewObject in Python) this is the connection between the document object and the QGraphicsItem.
Gui/TaskWiringSymboil - a dialog for creating a WiringSymbol and setting its properties. This dialog is invoked from a command and from the ViewProvider's setEdit method.
The more I study this question, the more it seems to me that it makes sense to use Tech Draw as a basis. Because needs to create a sheet feature, FeaturePython for each element, etc. Rewriting Tech Draw in Python requires the efforts of several people who do not exist. Although what Python is convenient for is for quick and easy code editing and making changes, even for novice programmers.
Too much time spent on code for drawing is not the main task for a good electrician's workbench.
I have a few questions, maybe you could answer them...
1) Even if I add mouse events to QtGui.QGraphicsScene then objects in QtGui.QGraphicsView become stationary. There is some kind of interception of events. Is there anyway to make events not eaten up and work there and there without blocking each other?
2) I can get mouse Events to QtGui.QGraphicsScene. But QtGui.QGraphicsView does not respond to the mouse in any way. Maybe QtGui.QGraphicsView does not accept mouse events at all and they need to be caught from QtGui.QGraphicsScene? I try to do sheet scaling, for via QtGui.QGraphicsView.wheelEvent(self, event) but it doesn't react in any way...
3) For some reason, when moving objects by mouse (setFlag(QtGui.QGraphicsItem.ItemIsMovable)), artifacts (arrays of lines) appear on the QtGui.QGraphicsView...
- artefacts.png (6.37 KiB) Viewed 1725 times
Perhaps this is a BoundingBox error... But the objects are created by means of the library, so Boundingbox should be fine.