I tried to adopt your python script published in https://forum.freecadweb.org/viewtopic. ... 5&p=379153.wandererfan wrote: ↑Sat Apr 30, 2022 12:55 pm In Python, TechDrawGui.addQGIToView(myFeature, myQGSvgItem) should do it. If not, we can add some functionality.
Code: Select all
import FreeCAD, FreeCADGui
import TechDraw, TechDrawGui
from PySide import QtGui, QtCore
from PySide import QtSvg # new inserted line
TDG = TechDrawGui
#class SimpleItem(QtGui.QGraphicsItem): # original line
class SimpleItem(QtSvg.QGraphicsSvgItem): # new inserted line
def __init__(self, parent = None):
super().__init__(parent)
self.Type = QtGui.QGraphicsItem.UserType + 501
self.setZValue(500)
def boundingRect(self):
penWidth = 10.0
return QtCore.QRectF(-100 - penWidth / 2, -100 - penWidth / 2,
200 + penWidth, 200 + penWidth)
def paint(self, painter, option, widget):
painter.drawRoundedRect(-100, -100, 200, 200, 50, 50)
view = App.ActiveDocument.View
qgSI = SimpleItem()
obj = TDG.addQGIToView(view, qgSI); # FreeCAD crash in this line
qgSI.setPos(0.0, 0.0)
As far as I could analyse, the following happenes (but I can be wrong):
In file AppTechDrawGuiPy.cpp, line 349 ff:
Code: Select all
QGraphicsItem* item = wrap.toQGraphicsItem(qgiPy);
if (item != nullptr) {
qgiv->addArbitraryItem(item);
the function toQGraphicsItem returns a pointer having an improper type.
Subsequently in file QGIView.cpp, line 678 ff:
Code: Select all
void QGIView::addArbitraryItem(QGraphicsItem* qgi)
{
if (qgi != nullptr) {
addToGroup(qgi);
qgi->show();
}
}