PDA

View Full Version : PyQt Signal and Slot Problem



HelderC
5th December 2011, 23:22
Hi guys.

I'm with a problem when using signal and slots in PyQt.
Actualy I can't connec the signal with the slot. I ever got the message:


Object::connect: No such slot Main::mousePress(QMouseEvent,int,int)
Object::connect: (receiver name: 'MainWindow')
Object::connect: No such slot Main::mouseMove(QMouseEvent,int,int)
Object::connect: (receiver name: 'MainWindow')
Object::connect: No such slot Main::mouseRelease(QMouseEvent,int,int)
Object::connect: (receiver name: 'MainWindow')


Look, some parts.
I have an QGraphicsView sub-class that emit signals of mouseMove, mousePress and mouseRelease:

def mousePressEvent(self, event):
# emitir o sinal
self.emit(SIGNAL('mousePressEvent(int, int, QMouseEvent)'),
event.pos().x(), event.pos().y(), event)

def mouseMoveEvent(self, event):
# emitir o sinal
self.emit(SIGNAL('mouseMoveEvent(int, int, QMouseEvent)'),
event.pos().x(), event.pos().y(), event)

def mouseReleaseEvent(self, event):
self.emit(SIGNAL('mouseReleaseEvent(int, int, QMouseEvent)'),
event.pos().x(), event.pos().y(), event)


And, in other class that implements the QGraphicsView sub class, I get the signals:


self.connect(
self.view, SIGNAL('mousePressEvent(QMouseEvent, int, int)'),
self, SLOT('mousePress(QMouseEvent, int, int)'))
self.connect(
self.view, SIGNAL('mouseMoveEvent(QMouseEvent, int, int)'),
self, SLOT('mouseMove(QMouseEvent, int, int)'))

self.connect(
self.view, SIGNAL('mouseReleaseEvent(QMouseEvent, int, int)'),
self, SLOT('mouseRelease(QMouseEvent, int, int)'))

...

@pyqtSlot(QMouseEvent, int, int)
def mousePress(self, event, x, y):
if (self.desLinha):
self.inicio = self.fim = self.view.mapToScene(QPoint(x,y));
self.linha = QGraphicsLineItem(QLineF(self.inicio, self.fim))
self.linha.setFlags(QGraphicsItem.ItemIsMovable)
print "%dx %dy" % (x, y)

self.cena.addItem(self.linha)

QGraphicsView.mousePressEvent(event)

@pyqtSlot(QMouseEvent, int, int)
def mouseMove(self, event, x, y):
if (self.desLinha):
self.fim = self.view.mapToScene(QPoint(x,y))
self.linha.setLine(QLineF(self.inicio, self.fim))

QGraphicsView.mouseMoveEvent(event)

@pyqtSlot(QMouseEvent, int, int)
def mouseRelease(self, event, x, y):
if (self.desLinha):
self.fim = self.view.mapToScene(QPoint(x,y))
self.linha.setLine(QLineF(self.inicio, self.fim))

QGraphicsView.mouseReleaseEvent(event)

How I said before, I'm ever getting the same error que I posted firstly.