I am trying to connect a signal from a created object and am getting an error. Here is a simplified version of my code:
class OverviewWindow(QMainWindow):
def __init__(self, projectClusters, users, contributorDict, userLastRevPerProj):
QMainWindow.__init__(self)
# Code....
def createUserNodes(self):
userNodes = {}
nodeSpread = 50
yPos = -400
nodeSpan = nodeSpread + 100
width = (len(self.usersFilt) - 1) * nodeSpan
xPos = 0 - (width / 2)
for user in self.usersFilt:
newItem = NodeItem(xPos, yPos, self.nodeDiameter, user, True)
newItem.nodeDoubleClicked.connect(self.dc)
userNodes[user] = newItem
self.graphicsScene.addItem(newItem)
xPos += nodeSpan
return userNodes
@pyqtSlot(str)
def dc(self, text):
print(text)
class NodeItem(QGraphicsItem):
nodeDoubleClicked = pyqtSignal(str)
def __init__(self, xPos, yPos, diameter, text, isUserNode):
super(NodeItem, self).__init__()
# Code...
def mouseDoubleClickEvent(self, event):
self.nodeDoubleClicked.emit(self.texts)
When trying to run it it give me this error:
line 84, in createUserNodes
newItem.nodeDoubleClicked[str].connect(self.dc)
TypeError: NodeItem cannot be converted to PyQt5.QtCore.QObject in this context
I have no idea what this means or how to fix it.
QGraphicsItem
does not inherit from QObject
, therefore it is not possible to emit a signal from an instance of QGraphicsItem
. You can solve this by subclassing QGraphicsObject
instead of QGraphicsItem
: http://doc.qt.io/qt-5/qgraphicsobject.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With