Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QFileDialog and modality problem.
QtWS25 Last Chance

[Solved] QFileDialog and modality problem.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bekos
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        Did you try "show ?":http://doc.qt.nokia.com/latest/qwidget.html#show

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bekos
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved