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

QFileDialog open on top of windows



  • Hi!
    I have window:

        def __init__(self, parent):  # инициализация
            super(DialogEpr, self).__init__()
            self.ui = uic.loadUi("dialogEpr.ui")
            self.ui.setWindowModality(QtCore.Qt.ApplicationModal)
    

    And I open QFileDialog, but QFileDialog opens under other windows.
    How open QFileDialog on top of windows?

    It's code QFileDialog:

    fileDialog = QFileDialog(self.ui)
            fileDialog.setWindowModality(QtCore.Qt.ApplicationModal)
            fileDialog.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
            fileDialog.setLabelText(QFileDialog.Accept, "Открыть")
            fileDialog.setLabelText(QFileDialog.Reject, "Отмена")
            fileDialog.setWindowTitle('Выбрать векторную карту')
            fileDialog.setNameFilters(["Файл ЭПР (*.rcs)"])
            pathFile = ""
            if fileDialog.exec():
                pathFile = fileDialog.selectedUrls()[0].toDisplayString().replace('file://', '')
    

    It is not work:

             fileDialog.setWindowFlags( QtCore.Qt.Window
                                          | QtCore.Qt.CustomizeWindowHint
                                          | QtCore.Qt.WindowTitleHint
                                          | QtCore.Qt.WindowCloseButtonHint )
    

  • Lifetime Qt Champion

    @Mikeeeeee said in QFileDialog open on top of windows:

    DialogEpr

    What type is it?



  • @jsulm said in QFileDialog open on top of windows:

    What type is it?

    QObject

    class DialogEpr(QObject):  
    
        def __init__(self, parent): 
            super(DialogEpr, self).__init__()
    
            self.ui = uic.loadUi("dialogEpr.ui")
            self.ui.setWindowModality(QtCore.Qt.ApplicationModal)  
    


  • @Mikeeeeee
    You seem to have both the parent/calling window/dialog and the file dialog being QtCore.Qt.ApplicationModal. Maybe this isn't a good idea/the cause of the problem, I don't know? At least try without and see if the behaviour is affected?



  • In result I use this:

    fileDialog = QFileDialog(self.ui)
            fileDialog.setWindowModality(QtCore.Qt.ApplicationModal)
            fileDialog.setOption(QFileDialog.DontUseNativeDialog)
    

Log in to reply