Results 1 to 3 of 3

Thread: Create a QFileDialog with similar behavior as the static function getExistingDirector

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default Create a QFileDialog with similar behavior as the static function getExistingDirector

    os : win7 64bits
    Qt : Qt5.2

    part 1
    Qt Code:
    1. dir_ = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
    2. dir_,
    3. QFileDialog::ShowDirsOnly
    4. | QFileDialog::DontResolveSymlinks);
    To copy to clipboard, switch view to plain text mode 


    part 2
    Qt Code:
    1. QFileDialog dialog(nullptr, tr("Open Directory"));
    2. dialog.setAcceptMode(QFileDialog::AcceptOpen);
    3. dialog.setFileMode(QFileDialog::DirectoryOnly);
    4. dialog.setOption(QFileDialog::ShowDirsOnly);
    5. dialog.setOption(QFileDialog::DontResolveSymlinks);
    6. if(dialog.exec()){
    7. dir_ = dialog.selectedFiles()[0];
    8. }else{
    9. dir_.clear();
    10. }
    To copy to clipboard, switch view to plain text mode 

    part 2 work fine, but it will minimize the main window after I select the directory
    part 1 would not minimize the main window after I select the directory, but I can't(or don't know)
    detect the "cancel" button is pressed or not

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Create a QFileDialog with similar behavior as the static function getExistingDire

    If the static function returns an empty string then the user pressed Cancel otherwise they pressed Ok.

    part 2 work fine, but it will minimize the main window after I select the directory
    The dialog has nothing to do with the minimized/normal/maximized state of the main window.

  3. The following user says thank you to ChrisW67 for this useful post:

    stereoMatching (2nd February 2014)

  4. #3
    Join Date
    Jan 2011
    Posts
    127
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default Re: Create a QFileDialog with similar behavior as the static function getExistingDire

    My bad, it do not minimize the mainWindow but do not keep it as a top widget
    I use raise() to solve this problem

Similar Threads

  1. strange behavior with QFileDialog::getExistingDirectory
    By cemoktra in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2013, 14:20
  2. Replies: 3
    Last Post: 30th January 2013, 10:43
  3. Replies: 11
    Last Post: 5th September 2012, 21:47
  4. static QEventLoop strange behavior
    By SABROG in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 13:04
  5. Replies: 4
    Last Post: 3rd May 2007, 09:15

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.