PDA

View Full Version : Create a QFileDialog with similar behavior as the static function getExistingDirector



stereoMatching
31st January 2014, 21:03
os : win7 64bits
Qt : Qt5.2

part 1

dir_ = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
dir_,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);


part 2

QFileDialog dialog(nullptr, tr("Open Directory"));
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setFileMode(QFileDialog::DirectoryOnly);
dialog.setOption(QFileDialog::ShowDirsOnly);
dialog.setOption(QFileDialog::DontResolveSymlinks) ;
if(dialog.exec()){
dir_ = dialog.selectedFiles()[0];
}else{
dir_.clear();
}

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

ChrisW67
1st February 2014, 00:44
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.

stereoMatching
2nd February 2014, 11:59
My bad, it do not minimize the mainWindow but do not keep it as a top widget
I use raise() to solve this problem