0

Why does this multiple class inheritance not work? It appears I'm doing something incorrect. I'm trying to create a baseclass that has a property of UID and when that property is change it calls self.update forcing the graphics item's paint event to be triggered. The reason for the baseclass is so i can implement this property across all other custom GraphicItems that I'll be eventually creating. Not all of them will be TextItems.

import os, sys, uuid
from Qt import QtWidgets, QtGui, QtCore

class AbstractNodeItem(QtWidgets.QGraphicsItem):
    def __init__(self, parent=None):
        super(AbstractNodeItem, self).__init__(parent)
        self.setFlags(self.ItemIsSelectable | self.ItemIsMovable)
        self.setZValue(0)

        # private
        self.m_uid = uuid.uuid4().hex

    # Getters/Setters
    def getUid(self):
        return self.m_uid

    def setUid(self, value=''):
        self.m_uid = value


class StickyNoteNodeItem(AbstractNodeItem, QtWidgets.QGraphicsTextItem):
    def __init__(self, parent=None):
        super(StickyNoteNodeItem, self).__init__(parent)


def printProperties(item):
    print '>>>>>', item.getUid()


a = AbstractNodeItem()
b = StickyNoteNodeItem()
printProperties(a)
printProperties(b)
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
  • change `class AbstractNodeItem(QtWidgets.QGraphicsItem):` to `class AbstractNodeItem(object):` and remove `a = AbstractNodeItem()` and `printProperties(a)` – eyllanesc Jan 13 '19 at 02:43
  • is doing multiple class inheristance bad if i plan on converting this to C++ qt? – JokerMartini Jan 13 '19 at 03:02
  • Not really, but the concept you should use is an interface. – eyllanesc Jan 13 '19 at 03:03
  • I agree, im not sure how to do that in pyside using python? Is that something I would do in Qt with C++ when i convert it? – JokerMartini Jan 13 '19 at 03:05
  • Although the concepts and implementations are similar in C ++ and python, there are slight differences that I would recommend you to try. And obviously test the concept first in basic classes (not Qt) since Qt has other restrictions. – eyllanesc Jan 13 '19 at 03:07
  • if you want all the QGraphicsItems to have the same class AbstractNodeItem I would recommend using templates in C++ – eyllanesc Jan 13 '19 at 03:09
  • I'm assuming some of the stuff you describe is not easily done in python pyside, which is why im doing it here first because it's easier and quicker to do – JokerMartini Jan 13 '19 at 03:10

0 Answers0