Results 1 to 6 of 6

Thread: QFileDialog::getOpenFileName - change label to "import"?

  1. #1
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default QFileDialog::getOpenFileName - change label to "import"?

    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!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QFileDialog::getOpenFileName - change label to "import"?

    Use this
    Qt Code:
    1. void QFileDialog::setLabelText (QFileDialog::Accept, "Import" )
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: QFileDialog::getOpenFileName - change label to "import"?

    I tried. But it does not work. Any other idea?

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileDialog::getOpenFileName - change label to "import"?

    Seems to work fine for me:
    Qt Code:
    1. #include <QApplication>
    2. #include <QDebug>
    3. #include <QtGui>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. d.setLabelText( QFileDialog::Accept, "whatever" );
    10. d.exec();
    11. qDebug() << d.selectedFiles();
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: QFileDialog::getOpenFileName - change label to "import"?

    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)"));

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFileDialog::getOpenFileName - change label to "import"?

    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.

Similar Threads

  1. "Change widget class on button click" problem
    By utkozanenje in forum Newbie
    Replies: 3
    Last Post: 23rd May 2011, 00:40
  2. Replies: 2
    Last Post: 29th July 2010, 19:37
  3. Replies: 3
    Last Post: 11th January 2009, 05:22
  4. "new QFileDialog" vs. "getSaveFileName" drive names
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2008, 13:11
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.