Reputation: 17049
How can I save some text to clipboard by pressing button? clipboard.setText("gg")
works by itself
widget.connect(button, QtCore.SIGNAL('clicked()'), clipboard.setText("text") )
throw error, you can only use instance.methodName
widget.connect(button, QtCore.SIGNAL('clicked()'), clipboard, QtCore.SLOT('setText("text")') )
do nothing.
What is wrong?
Upvotes: 0
Views: 530
Reputation: 33397
First, there's a much better way to connect signals to slots on PyQt:
button.clicked.connect(self.method)
You can use lambda functions to pass extra arguments to methods. Then you call
button1.clicked.connect(lambda : clipboard.setText('btn one'))
button2.clicked.connect(lambda : clipboard.setText('btn two'))
When you pass a function call, in fact the interpreter is evaluating the call and trying to pass the result to the SIGNAL/SLOT connection. That's why your first example doesn't work.
I've written something similar here: https://stackoverflow.com/questions/...from-other-functions
Upvotes: 1