views:

183

answers:

1

From research on Stack Overflow and other sites I'm 99% sure that the problem I'm having is due to incorrect importing. Below is a QLabel sub class that I'm using to respond to some mouse events:

import Qt
import sys

class ASMovableLabel(Qt.QLabel):

    def mouseReleaseEvent(self, event):

        button = event.button()
        if button == 1:
            print ('LEFT CLICK')

    def mousePressEvent(self, event):

        button = event.button()
        if button == 1:
            print ('LEFT CLICK')
        elif button == 3:
            print ('RIGHT CLICK')
            self.setLayout()

    def mouseMoveEvent(self, event):
        print ("you moved the mouse: %f, %f", event.x, event.y)
        self.frameRect.setTopLeft(Qt.QPoint(event.x, event.y))

When mouseMoveEvent is triggered I get the following error:

    self.frameRect.setTopLeft(Qt.QPoint(event.x, event.y))
AttributeError: 'builtin_function_or_method' object has no attribute 'setTopLeft'

The other solutions to this type of error I've seen have revolved around the name space, so I would or would not need to include Qt. before all the Qt classes but this error is much farther down in the Qt objects. Please point out my mistake!

I have also tried:

from PyQt4 import Qt

It gives the same error

UPDATE: based on Messa's comment I made few changes:

import Qt
import sys

class ASMovableLabel(Qt.QLabel):

    def mouseReleaseEvent(self, event):

        button = event.button()
        if button == 1:
            print ('LEFT CLICK')

    def mousePressEvent(self, event):

        button = event.button()
        if button == 1:
            print ('LEFT CLICK')
        elif button == 3:
            print ('RIGHT CLICK')
            self.setLayout() #this won't set to nil

    def mouseMoveEvent(self, event):
        self.frameRect().setTopLeft(Qt.QPoint(event.globalX(), event.globalY()))

So it seems that in Python the dot syntax are function calls and need to include that trailing "()". This doesn't include self ( i.e. self().something() )

+1  A: 

Try

self.frameRect().setTopLeft(Qt.QPoint(event.x, event.y))

instead of

self.frameRect.setTopLeft(Qt.QPoint(event.x, event.y))
Messa