Results 1 to 3 of 3

Thread: QLineEdit + QCompleter: returnPressed signal

  1. #1
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default QLineEdit + QCompleter: returnPressed signal

    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

    Qt Code:
    1. # connect the activated signal to do custom handling
    2. self.connect(self.__completer, QtCore.SIGNAL("activated(QString)"), self.__text_activated)
    3.  
    4. # connect returnpressed() signal of the lineedit
    5. self.connect(self.__first_line, QtCore.SIGNAL("returnPressed()"), self.__handle_first_line_enter)
    6. self.connect(self.__second_line, QtCore.SIGNAL("returnPressed()"), self.__handle_second_line_enter)
    To copy to clipboard, switch view to plain text mode 

    "__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
    Last edited by wysota; 21st September 2010 at 12:50.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit + QCompleter: returnPressed signal

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit + QCompleter: returnPressed signal

    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.
    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

Similar Threads

  1. Replies: 4
    Last Post: 21st January 2011, 01:27
  2. How get signal returnPressed in QTextEdit
    By Roszko in forum Qt Programming
    Replies: 13
    Last Post: 30th December 2009, 09:59
  3. Replies: 1
    Last Post: 12th October 2008, 08:21
  4. QSpinBox and returnPressed() Signal
    By BeS in forum Newbie
    Replies: 2
    Last Post: 14th October 2006, 19:23
  5. QLineedit::returnPressed() closes dialog?
    By geranol in forum Newbie
    Replies: 2
    Last Post: 6th January 2006, 10:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.