Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
1.1.1
-
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_()