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:
{
Q_OBJECT
public:
explicit myQFileDialog
(QWidget *parent
= 0);
void initLineEdit
(const QString initFileName
) { QList<QLineEdit*> lineEdits = this->findChildren<QLineEdit*>();
for (int i = 0; i < lineEdits.count(); ++i)
if (QString::compare(lineEdits.
at(i
)->objectName
(),
"fileNameEdit", Qt
::CaseInsensitive) == 0) { lineEdits.at(i)->setText(initFileName);
return;
}
}
signals:
public slots:
};
class myQFileDialog : public QFileDialog
{
Q_OBJECT
public:
explicit myQFileDialog(QWidget *parent = 0);
void initLineEdit(const QString initFileName) {
QList<QLineEdit*> lineEdits = this->findChildren<QLineEdit*>();
for (int i = 0; i < lineEdits.count(); ++i)
if (QString::compare(lineEdits.at(i)->objectName(), "fileNameEdit", Qt::CaseInsensitive) == 0) {
lineEdits.at(i)->setText(initFileName);
return;
}
}
signals:
public slots:
};
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.
Bookmarks