Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFileDialog with strange behavior



  • Hello,

    first of all i develop under mac 10.14.6 (Mojave) using Qt 5.15.0.
    in my program i use QFileDialog as follow:

    this->fileDialog = new QFileDialog(window());
    this->fileDialog->setWindowFlags(Qt::Sheet);
    this->fileDialog->setWindowModality(Qt::WindowModal);
    this->fileDialog->setModal(true);
    ...
    this->fileDialog->exec()
    

    The strange thing is here that the dialog opens on the right position but than jumps down with a certain offset Y.
    screenshot.png

    I try to "fix" the position of QFileDialog with setGeometry(0, 0, 500, 400) but this without success.

    I am grateful for any help.



  • @Quorn-Julio said in QFileDialog with strange behavior:

    this->fileDialog = new QFileDialog(window());

    This looks weird... Replace window() with this or some other valid parent and try if your dialog "jumps" again

    @Quorn-Julio said in QFileDialog with strange behavior:

    this->fileDialog->setWindowModality(Qt::WindowModal);
    this->fileDialog->setModal(true);

    This is redundant... first line sets fileDialog window to WindowModal, the second overrides this setting with ApplicationModal, which is pretty much the same in a parent-child-hierarchy

    EDIT:

    And there is also this:

    Qt::Sheet

    Indicates that the window is a sheet on macOS. Since using a sheet implies window modality, the recommended way is to use QWidget::setWindowModality(), or QDialog::open(), instead.
    (From: https://doc.qt.io/qt-5/qt.html#WindowType-enum)

    So I guess, using Qt::Sheet together with setModal(true) is not recommended on MacOS.
    If this causes your jump?! I don't know :)



  • @Pl45m4

    Thank you so much!

    QDialog::open()
    

    works properly / as expected. i wonder why QDialog::exec does not!
    I would have expected the same behavior.


Log in to reply