Results 1 to 2 of 2

Thread: Trapping key press events in the QFileDialog file name line edit

  1. #1
    Join Date
    Oct 2009
    Posts
    38
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Unhappy Trapping key press events in the QFileDialog file name line edit

    Hi all,

    I posted back in February about a problem I was having getting ahold of and reliably enabling/disabling the QFileDialog Open button. Here's the link, but you don't have to read if you don't want to. This is a new issue coming up from the derivation from QFileDialog.

    http://www.qtcentre.org/threads/5807...ht=open+button

    I had installed an event filter on the Open button, once I got ahold of it, in order to stop it from being enabled when I had disabled it. Now I'm finding that I can't trap text changes in the QLineEdit for file name when I connect to the textChanged() signal. I assume it's because the base QFileDialog is catching those and not passing them on.

    The event filter works fine, but only when I type in letters that are *not* in any filename in the file list. If there, for instance, are three files that start with the string "foo", then typing 'f' as the first character does not get trapped in this event filter. If all three files continue with the letter 'b', as in "foob", and I type a 'c', then and only then do I get into the event filter and into the if KeyRelease block. This tells me that the QFileDialog is blocking me from getting letters that correspond to existing filenames. In fact, the dialog is showing a list of possible files in a dropdown at the bottom edge of the file name line edit field.

    This event filter looks as following:

    Qt Code:
    1. bool DtLoggerTapeDialog::eventFilter(QObject* obj, QEvent* event)
    2. {
    3. if (obj == myOpenButton)
    4. {
    5. if (event->type() == QEvent::EnabledChange)
    6. {
    7. // code for handling the Open button goes here
    8. return true;
    9. }
    10. else
    11. return false;
    12. }
    13. else if (obj == myFileNameLineEdit)
    14. {
    15. if (event->type() == QEvent::KeyRelease)
    16. {
    17. // code for handling the QLineEdit goes here
    18. return true;
    19. }
    20. else
    21. return false;
    22. }
    23.  
    24. // pass unfiltered events on to the parent class
    25. return QFileDialog::eventFilter(obj, event);
    26. }
    To copy to clipboard, switch view to plain text mode 

    Does anyone have a suggestion as to how I can get passed this issue? I have updated the dialog to disable the Open button until the correct internal format of file is selected in the file list (as shown in the link above), only to find when I type a name, I don't have the ability to enable the Open button for a typed name that exists in the file list. This is the last thing I have to do with this dialog, but I'm stumped as to what else I should look at.

  2. #2
    Join Date
    Oct 2009
    Posts
    38
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Thumbs up Re: Trapping key press events in the QFileDialog file name line edit

    Ok, so embarrassment reins here. Problem with using the signals was that, in the connect, I hadn't specified the signal/slot parameter list signature correctly, so it just silently ignores my connect. I will start asserting my connects from now on to make sure they connect properly.

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Replies: 2
    Last Post: 12th October 2010, 20:50
  3. Replies: 3
    Last Post: 26th August 2010, 08:57
  4. Replies: 2
    Last Post: 10th November 2009, 06:17
  5. Replies: 1
    Last Post: 17th July 2009, 08:22

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
  •  
Qt is a trademark of The Qt Company.