PDA

View Full Version : QLineEdit + QCompleter: returnPressed signal



thefriedc
21st September 2010, 13:20
hi,

i've got a really annoying problem with QLineEdit AND QCompleter. i develop with pyqt4 but i think it does not make any difference in this case.
my situation:

i build a QDialog with two QLineEdit elements. both are connected to a (different) QCompleter instance. i customized the behaviour of the QComleter to enable inline completion, after a defined separator has been entered.
for this purpose i connect my handler to the "activated(QString)" signal of the completer. this is emitted, when a suggested value of the QCompleter has been selected.
when this signal is emitted - i manually write the new content to the lineEdit object.

whenever i choose a suggestion of the completer by hitting enter, the "returnPressed()" signal of the QLineEdit gets fired. just after the execution of the connected slot, the signal "activated(QString)" is emitted.
the problem is, i have a custom slot connected to the returnPressed() signal of the lineEdit instances. these should just come into action if there was an eplicit "hit enter" just in the lineedit and not in the completer.

has anybody an idea how to ignore the returnPressed() signal when just choosing a suggestion from the completer?
why is there even a returnPressed() signal? the completer uses a QListView afaik - and this does not emit a returnPressed() signal.

i would really appreciate your help!

thnx - chris

here is an example, of what i do in my code:

-> it is python code - but its easily understandable



# connect the activated signal to do custom handling
self.connect(self.__completer, QtCore.SIGNAL("activated(QString)"), self.__text_activated)

# connect returnpressed() signal of the lineedit
self.connect(self.__first_line, QtCore.SIGNAL("returnPressed()"), self.__handle_first_line_enter)
self.connect(self.__second_line, QtCore.SIGNAL("returnPressed()"), self.__handle_second_line_enter)


"__handle_first_line_enter()" or "__handle_second_line_enter()" are always called befor the "__text_activated()"
this is, what it is ment to get rid of

SixDegrees
21st September 2010, 13:47
Note that the more standard way of selecting a completer suggestion is to hit the 'tab' key; enter accepts the current contents of the QLineEdit. In the interest of consistent UI experience, I'd follow that convention rather than ganging up on 'enter' and making it mean two different things.

thefriedc
21st September 2010, 17:21
thanks for your reply.

well, i just tested it and tab (with highlighted suggestion) does nothing else, than switching to the next qwidget in the taborder, without doing any completion. :confused:
im developing under mac osx 10.5.8.

nevertheless if tab is the key of choice - i would like to catch a "returnPressed" in the completer to avoid maloperation by the user.

generally: why do i get a returnPressed signal, from lineEdit when i hit enter while a ListView has the focus? i did not find sufficient information on the web, how the signal/slot thing works in the widget hierarchy. is a signal passed to the parent, if there is no slot handling it?

greets