Qfiledialog setting the filter programmatically

  • i have a qfiledialog embedded into another dialog. in this dialog i have number of radiobuttons and when i click them i want the qfiledialog filter to be set to a desired QString and the file dialog to apply this filter. i have tried selectNameFilter but the file dialog does not update and the current filter does not change to the one specified in the QString.

    is it possible to do something like this programmatically?

    thanks for any help.

  • You set all the filters corresponding to your radio buttons via setNameFilter()?

  • i found the problem by looking at the code. it appears that if you have setOption(QFileDialog::DontUseNativeDialog) then you MUST setOption(QFileDialog::HideNameFilterDetails) otherwise, the selectNameFilter will not work. i looked at the Qt qfiledialog.cpp code and that is how i found it. i personally think they should always go through the qt_make_filter_list statement below.

    @ if (testOption(HideNameFilterDetails)) {
    i = d->qFileDialogUi->fileTypeCombo->findText(qt_strip_filters(qt_make_filter_list(filter)).first());
    } else {
    i = d->qFileDialogUi->fileTypeCombo->findText(filter);
    if (i >= 0) {

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.