Results 1 to 11 of 11

Thread: QFileDialog set default name

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileDialog set default name

    This is for the native dialogs, i.e. static function of QFileDialog like getSaveFileName etc. and when path PLUS file name is passed as the argument for start location/path then that file name is automatically filed with dialog file name. (and I have that working fine).

    What I ask is how to set default QFileDialog (i.e. Qt dialog) file name. In src I couldn't find any way to access that line edit for file name.

    EDIT:
    ------------------------
    Because copy is disabled in QFileDialog I can't access the d pointer to set Ui line edit text for file name.
    Modifying src is trouble some, because that force to redistribute modified Qt libs, also (I didn't checked it so maybe Im wrong) QFileDialog can be customized to disable this lineEdit so...

    What I did, to set custom file name in QFileDialog (Qt one not the native one) is this:

    Qt Code:
    1. class myQFileDialog : public QFileDialog
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit myQFileDialog(QWidget *parent = 0);
    6.  
    7. void initLineEdit(const QString initFileName) {
    8. QList<QLineEdit*> lineEdits = this->findChildren<QLineEdit*>();
    9.  
    10. for (int i = 0; i < lineEdits.count(); ++i)
    11. if (QString::compare(lineEdits.at(i)->objectName(), "fileNameEdit", Qt::CaseInsensitive) == 0) {
    12. lineEdits.at(i)->setText(initFileName);
    13. return;
    14. }
    15. }
    16.  
    17. signals:
    18.  
    19. public slots:
    20.  
    21. };
    To copy to clipboard, switch view to plain text mode 

    Note:
    If trolls decide to change name of the line edit from fileNameEdit to anything else then this function will simply dont work the way it suppose to.
    Last edited by Talei; 15th June 2012 at 13:15.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. Replies: 9
    Last Post: 26th May 2010, 22:16
  2. Replies: 1
    Last Post: 20th January 2010, 22:59
  3. How set default file to save in QFileDialog
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 12:09
  4. why QFileDialog does not display the default winxp dialog?
    By mismael85 in forum Qt Programming
    Replies: 5
    Last Post: 21st March 2008, 13:39
  5. QFileDialog::getSaveFileName default extension
    By elcuco in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2007, 20:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.