Reputation: 839
I've been having some trouble with create click of buttons in PyQT. when i create click of button as below , this picture can't save
cv.SetImageROI(image, (pt1[0],pt1[1],pt2[0] - pt1[0],int((pt2[1] - pt1[1]) * 1)))
if self.Button.click():
cv.SaveImage('example.jpg', image)
cv.ResetImageROI(image)
Upvotes: 3
Views: 25432
Reputation: 17455
The problem in your code is that you are performing a programmatic click on the button calling QPushButton.click
on the line if self.Button.click():
, what you need to do is to connect the signal QPushButton.clicked
to a proper slot on your code. Singals and Slots is the way Qt handle some significant events that may occur on the object. Here I'll drop you an example, hope it helps:
import PyQt4.QtGui as gui
#handler for the signal aka slot
def onClick(checked):
print checked #<- only used if the button is checkeable
print 'clicked'
app = gui.QApplication([])
button = gui.QPushButton()
button.setText('Click me!')
#connect the signal 'clicked' to the slot 'onClick'
button.clicked.connect(onClick)
#perform a programmatic click
button.click()
button.show()
app.exec_()
Note: To understand the underlying behavior read the docs of Qt/PyQt.
Upvotes: 8