title: Differentiate single click from double click in pyside
body: <p>I have tried to implement in Pyside the method described in <a href="https://stackoverflow.com/questions/18021691/how-to-distinguish-between-mousereleaseevent-and-mousedoubleclickevent-on-qgrapn" title="How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGrapnhicsScene">How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGrapnhicsScene</a>, but I had to add a crufty flag to keep it from showing single click after the second button release in a double click.  </p>
  
  <p>Is there a better way?</p>
  
  <pre><code>import sys
  from PySide import QtGui, QtCore
  
  class Example(QtGui.QWidget):
  
      def __init__(self):
          super(Example, self).__init__()
          """an attempt to implement 
          https://stackoverflow.com/questions/18021691/how-to-distinguish-between-mousereleaseevent-and-mousedoubleclickevent-on-qgrapn
          main()
              connect(timer, SIGNAL(timeout()), this, SLOT(singleClick()));
          mouseReleaseEvent()
              timer-&gt;start();
          mouseDoubleClickEvent()
              timer-&gt;stop();
          singleClick()
              // Do single click behavior
          """
          self.timer = QtCore.QTimer()
          self.timer.setSingleShot(True)
          # had to add a "double_clicked" flag
          self.double_clicked = False
          self.timer.timeout.connect(self.singleClick)
  
          self.setGeometry(300, 300, 250, 150)
          self.setWindowTitle('Single click, double click')    
          self.show()
  
      def mouseReleaseEvent(self, event):
          if not self.double_clicked:
              self.timer.start(200)
          else:
              self.double_clicked = False
  
      def mouseDoubleClickEvent(self, event):
          self.timer.stop()
          self.double_clicked = True
          print 'double click'
  
      def singleClick(self):
          print 'singleClick'
  
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  </code></pre>