[PyQt] Double Click event from QPushButton
lj
larry at foxgulch.com
Thu Jul 24 17:01:08 BST 2008
This code (~40 lines) builds a dialog window with a single pushbutton in
the middle of it. I need to be able to detect a left mouse button
double click on the push button. As is, I can detect double clicks
outside the pushbutton anywhere on the dialog window and even right
mouse button double clicks on the pushbutton but not left button
double clicks, which is what I desire.
Would you please tell this newbie what he is doing wrong. Thank you,
Larry
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
import sys
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,335,166).size()).expandedTo(Dialog.minimumSizeHint()))
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(100,50,80,28))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog",
"Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Dialog",
"PushButton", None, QtGui.QApplication.UnicodeUTF8))
class TestDlg(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(TestDlg, self).__init__(parent)
self.setupUi(self)
self.connect(self.pushButton,
SIGNAL("itemDoubleClicked(QListWidgetItem *)"), self.printTest)
def mouseDoubleClickEvent(self, event):
print "DoubleClick"
def mouseClickEvent(self, event):
print "Click"
def contextMenuEvent(self, event):
print "Context"
def mousePressEvent(self, event):
print "Mouse Press"
def printTest(self, widgetItem):
print "Test"
if __name__ == "__main__":
app = QApplication(sys.argv)
form = TestDlg()
form.show()
app.exec_()
More information about the PyQt
mailing list