Hi,

I used to use the decorator which I believed was "correct" according to the 
PyQt documents. Then I realised there were many instances where I'd 
forgotten to use it, but everything still worked, so now I generally don't 
bother. It may still be good practice and necessary in some cases: 
https://stackoverflow.com/questions/14421897/is-the-pyside-slot-decorator-necessary/14431607#14431607

I think if you want to get it to work, you need to tell the decorator that 
the wrapped function accepts a parameter. In this case I believe the evt is 
an instance of QMouseEvent, so the decorator should be something like 
(import of QtGui needed of course):
@pyqtSlot(QtGui.QMouseEvent)

Also, as far as I can tell there aren't code blocks in the new Google 
Groups interface, which is a little backwards. Happy to be corrected on 
that!

Patrick
On Wednesday, 14 July 2021 at 3:50:34 am UTC+9:30 James wrote:

> Hi all,
>
> The code below works as expected to get the position of a click in a 
> GraphicsLayoutWidget. But if I uncomment the @pyqtSlot() line, then I get 
> the following error when I click in the GLW:
>
>     TypeError: onClick() missing 1 required positional argument: 'evt'
>
> Should I not be using @pyqtSlot() decorator?
>
> James
>
> PS: I do not see an option to syntax-highlight code blocks in this group. 
> Can that be enabled?
>
> import sys
> import pyqtgraph as pg
> from PyQt5 import QtWidgets as qtw
> from PyQt5.QtCore import pyqtSlot
>
> class MainWindow(qtw.QMainWindow):
>     def __init__(self, *args, **kwargs): super(MainWindow, 
> self).__init__(*args, **kwargs)
>
>         self.glw = pg.GraphicsLayoutWidget()
>         self.setCentralWidget(self.glw)
>         self.glw.scene().sigMouseClicked.connect(self.onClick)
>         self.show()
>
>     #@pyqtSlot()                                                          
>                                                                     
>     def onClick(self, evt):
>         print("glw clicked")
>         print(evt.scenePos())
>
> if __name__ == "__main__":
>     app = qtw.QApplication(sys.argv)
>     win = MainWindow()
>     app.exec_()
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/862ce769-447b-4d35-aaf0-eaa899240641n%40googlegroups.com.

Reply via email to