[Solved] QFileDialog and modality problem.



  • Hello guys! :)

    I am trying to achieve something very simple but I guess I do something really wrong!
    I want to have an open file dialog box that when it is shown the user wont be able to click or focus on an other widget of the application. In order to do that I think I have to set modal to true and window modality to Qt::ApplicationModal. Unfortunately this does not work. Although I did the same for a QMessageBox and it worked perfectly. Do I need to do something more when I am working with QFileDialog? The only way to achieve what I want is NOT to set a parent for me QFileDialog. But this is not a solution because I want to set the parent.

    Here is my code:
    @
    std::string XMLStateManager::showOpenDialog( void ) const
    {
    QFileDialog dialog;
    dialog.setParent( _mainWindow ); // If I remove this line it works. But this is not a solution. I didn't have to remove it to make the QMessageBox to work.
    dialog.setAcceptMode(QFileDialog::AcceptOpen);
    dialog.setFileMode(QFileDialog::ExistingFile);
    dialog.setDefaultSuffix("mex");
    dialog.setNameFilter("My Extension(*.mex)");
    dialog.setViewMode(QFileDialog::Detail);
    dialog.setWindowModality( Qt::ApplicationModal );
    dialog.setModal(true);

    if( !dialog.exec() )
            return std::string();
    
    return dialog.selectedFiles()[0].toStdString();
    

    }
    @

    Am I missing something here? Thanks for your time guys!



  • The "QDialog docs":http://doc.qt.nokia.com/latest/qdialog.html state:

    bq. Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget. This function allows you to explicitly set the window flags of the reparented widget; using the overloaded function will clear the window flags specifying the window-system properties for the widget (in particular it will reset the Qt::Dialog flag).

    So, did you try to set the parent in the constructor?

    @
    QFileDialog dialog(_mainWindow);
    @

    Did you consider one of the convenience static methods, especially "QFileDialog::getOpenFileName() ":http://doc.qt.nokia.com/4.7/qfiledialog.html#getOpenFileNames seems to do what you are implementing.





  • You are right dude, my bad I am sorry. Setting it at the constructor works! I should be more careful next time! Thank you very much!

    [quote author="Volker" date="1304607073"]The "QDialog docs":http://doc.qt.nokia.com/latest/qdialog.html state:

    bq. Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget. This function allows you to explicitly set the window flags of the reparented widget; using the overloaded function will clear the window flags specifying the window-system properties for the widget (in particular it will reset the Qt::Dialog flag).

    So, did you try to set the parent in the constructor?

    @
    QFileDialog dialog(_mainWindow);
    @

    Did you consider one of the convenience static methods, especially "QFileDialog::getOpenFileName() ":http://doc.qt.nokia.com/4.7/qfiledialog.html#getOpenFileNames seems to do what you are implementing.[/quote]


Log in to reply
 

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