Yes, that was it. I made the following changes to my code. When I grab the Open button in the constructor, I install the event filter on that button. I overrode the eventFilter() function as shown. Fixed my problem. Thanks for the help. Now I know...
: QFileDialog(parent, tr
("Load Correct Format"), startdir
),
myOpenButton(0)
{
// constructor - on setting the myOpenButton pointer, I register
// the event filter on that button.
myOpenButton->installEventFilter(this);
}
{
if (obj == myOpenButton)
{
QEvent::Type type
= event
->type
();
bool valid = validSelection();
bool enabled = myOpenButton->isEnabled();
if (type
== QEvent::EnabledChange && enabled
&& !valid
) {
// don't allow QFileDialog to alter the state of the
// Open button. This is to be handled locally in the
// MyFileDialog::fileSelectionChanged() function.
myOpenButton->setEnabled(false);
return true;
}
else
return false;
}
// pass unfiltered events on to the parent class
}
MyFileDialog::MyFileDialog(QWidget* parent, QString startdir)
: QFileDialog(parent, tr("Load Correct Format"), startdir),
myOpenButton(0)
{
// constructor - on setting the myOpenButton pointer, I register
// the event filter on that button.
myOpenButton->installEventFilter(this);
}
bool MyFileDialog::eventFilter(QObject* obj, QEvent* event)
{
if (obj == myOpenButton)
{
QEvent::Type type = event->type();
bool valid = validSelection();
bool enabled = myOpenButton->isEnabled();
if (type == QEvent::EnabledChange && enabled && !valid)
{
// don't allow QFileDialog to alter the state of the
// Open button. This is to be handled locally in the
// MyFileDialog::fileSelectionChanged() function.
myOpenButton->setEnabled(false);
return true;
}
else
return false;
}
// pass unfiltered events on to the parent class
return QFileDialog::eventFilter(obj, event);
}
To copy to clipboard, switch view to plain text mode
Bookmarks