PDA

View Full Version : QFileDialog::getOpenFileName - change label to "import"?



marc2050
3rd June 2011, 05:07
Hi.

When I use QFileDialog::getOpenFileName to let user choose a file to import, the dialog's button reads "open". Is it possible to change that button to "Import" rather than open? It is not a big deal but it makes my application more in line with the action the user is doing.

Thanks!

Santosh Reddy
3rd June 2011, 07:01
Use this
void QFileDialog::setLabelText (QFileDialog::Accept, "Import" )

marc2050
4th June 2011, 08:26
I tried. But it does not work. Any other idea?

stampede
4th June 2011, 09:40
Seems to work fine for me:


#include <QApplication>
#include <QDebug>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QFileDialog d;
d.setLabelText( QFileDialog::Accept, "whatever" );
d.exec();
qDebug() << d.selectedFiles();

return a.exec();
}

marc2050
4th June 2011, 10:15
I did this. Does not seem to work.


QFileDialog d;
d.setLabelText( QFileDialog::Accept, "whatever" );
QString fileName = d.getOpenFileName(this, tr("Import File"),
importfilename,
tr("jpg (*.jpg)"));

stampede
4th June 2011, 10:38
getOpenFileName is static method, it will create default file dialog inside, will not use your dialog object. You need to call "exec" to use your dialog with changed label.