Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to use signal and slot in Python plugin which will invoke pya.Qt

I'm now developing a plugin upon klayout in Python.

I have a class derived from pya.QWidget as following:

class MyWidget(pya.QWidget):
   def  __init__(self):
          super().__init()__
          self.pushbutton_one = pya.QPushButton(self)         
          self.pushbutton_one.clicked.connect(self.clicked)

   def  clicked(self):
          print("clicked")

It seems the pyqt connect syntax does not work, I get an error.
So I try to use pya.QObject.connect(self.pushbutton_one, "2clicked()", self, "1clicked()"), but it does not work either.

so I wonder how could I use emit, Q_SIGNALS, Q_SLOTS, connect in python code which will invoke Qt interfaces exposed by KLayout.

Comments

  • edited November 4

    Hi William,

    KLayout doesn't use pyqt. Signals can be bound directly to methods, so in fact no slots need to be defined.

    It's as simple as this:

    self.pushbutton_one.clicked = self.clicked
    

    Matthias

  • Hi, Matthias

    Now it works. Thanks for your comment.

    William.

Sign In or Register to comment.