Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-204

QCompleter activated signal doesn't respond to mouse clicks.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 1.1.1
    • PySide
    • None

    Description

      Start typing in the line edit, and select a completion with the arrow keys and press enter. This will call the test(), method and print. However, if you select a completion with the mouse it will not work. There is a workaround where the test() method can be connected via a lambda function and it will behave correctly.

      Test case:

      from PySide import QtGui, QtCore
      
      class TestLE( QtGui.QLineEdit  ):
      
      	def __init__( self, parent = None ):
      		QtGui.QLineEdit.__init__( self, parent = parent )
      		self._completer = QtGui.QCompleter()
      		self._completer.setModel( self.__getModel() )
      		
      		# This line will cause the signal to be disconnected after the completer is clicked on with the mouse,
      		# but not if a completion is navigated to with the arrow keys and enter pressed.
      		self._completer.activated[QtCore.QModelIndex].connect( self.test )
      						
      		# This is connecting the same signal, but via a lambda wrapper function. This will work correctly for
      		# mouse clicks and keyboard enter presses.
      		# self._completer.activated[QtCore.QModelIndex].connect( lambda index : self.test(index) )
      		
      		self.setCompleter( self._completer )
      	
      	def __getModel( self ):
      		m = QtGui.QStandardItemModel( parent = self )
      		i = QtGui.QStandardItem( 'test' )
      		m.appendRow( i )
      		i2 = QtGui.QStandardItem( 'test2' )
      		m.appendRow( i2 )
      		return m
      		
      	def test( self, index ):
      		print 'index', index
      		
      
      if __name__ == '__main__':
      	app = QtGui.QApplication([])
      	
      	tle = TestLE()
      	tle.show()
      	
      	app.exec_()
      

      Attachments

        1. pyside-204.py
          1 kB
          Christian Tismer
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            wpb william bryant
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes