PDA

View Full Version : Trapping key press events in the QFileDialog file name line edit



bmahf
5th March 2014, 02:29
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/58071-QFileDialog-Enable-Disable-quot-Open-quot-button-in-inherited-class-not-working?highlight=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:



bool DtLoggerTapeDialog::eventFilter(QObject* obj, QEvent* event)
{
if (obj == myOpenButton)
{
if (event->type() == QEvent::EnabledChange)
{
// code for handling the Open button goes here
return true;
}
else
return false;
}
else if (obj == myFileNameLineEdit)
{
if (event->type() == QEvent::KeyRelease)
{
// code for handling the QLineEdit goes here
return true;
}
else
return false;
}

// pass unfiltered events on to the parent class
return QFileDialog::eventFilter(obj, event);
}


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.

bmahf
12th March 2014, 17:50
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.