开发者

PyQt4 - Cannot use QObject's functions in class inherited from QGraphicsItem (which inherits QObject)

开发者 https://www.devze.com 2023-02-14 07:09 出处:网络
I wrote python code looking something like this: class Regularblock(QGraphicsItem): def __init__(self):

I wrote python code looking something like this:

class Regularblock(QGraphicsItem):
    def __init__(self):
        super(QGraphicsItem).__init__()
        self.startTimer(100)
    def timerEvent(self, QTimerEvent):
开发者_如何转开发        do_something

But when I try to initialize an instance of Regularblock, I get "AttributeError: 'Regularblock' object has no attribute 'startTimer'". Why does this happen? Am I missing something big?


Short answer: I think QGraphicsItem is not actually a subclass of QObject. Have a look here; it is not listed as one of the QOject's direct subclasses. I'm not 100% sure, but perhaps you should be using QGraphicsObject ?

0

精彩评论

暂无评论...
验证码 换一张
取 消