Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-4419

QFileDialog: Different behaviour for static and non-static method

XMLWordPrintable

    • 71b3a015d5f051c732646ead395e56a609cc51af

      In a custom "file save as" dialog (derived from QFileDialog) the file name displayed in the text box is not selected when the dialog pops up.
      The cursor is blinking behind the file name and you have to delete the text instead just to overwrite it (like in a standard windows "Save as" dialog).

      This behaviour only occurs when invoking the dialog by calling exec().
      When using the static method "getSaveFileName()" everything is fine.

      The reason for this is that only in the protected constructor of QFileDialog (used by the static method ) the command

      d->lineEdit()->selectAll();

      is executed.

      The behavoiur should be the same as in the native windows dialog.

      Here some code snippets to reproduce the different behaviour:
      (tested with WindowsXP / VisualStudio 2005 / Qt 4.5.2)

      // Method 1 (non static)

      QDir dir(m_strFile); 
      QFileDialog testdlg(this, "Test", dir.absolutePath()); 
      
      testdlg.setAcceptMode(QFileDialog::AcceptSave); 
      testdlg.setConfirmOverwrite (true); 
      testdlg.setFileMode(QFileDialog::AnyFile); 
      testdlg.setDirectory(dir.absolutePath()); 
      testdlg.setFilter("*.txt *.ktr"); 
      
      if (testdlg.exec() == QDialog::Accepted) 
      { 
      QStringList files = testdlg.selectedFiles(); 
      ... 
      } 
      

      // Method 2 (static)

      QString fileName = QFileDialog::getSaveFileName(this, "Test", dir.absolutePath(), "*.txt *.ktr", NULL, QFileDialog::DontUseNativeDialog);
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            menard Alexis Menard (closed Nokia identity) (Inactive)
            mpejcoch Martin Pejcoch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes