コード例 #1
0
def showSelectProjectDialog(parent: QWidget = None) -> Optional[Path]:
    dialog = QFileDialog(parent, Qt.Dialog)
    dialog.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Dialog)
    dialog.setAcceptMode(QFileDialog.AcceptSave)
    dialog.setLabelText(QFileDialog.LookIn, "Select project folder")
    dialog.setFileMode(QFileDialog.Directory)
    dialog.setOption(QFileDialog.ShowDirsOnly, True)
    dialog.setViewMode(QFileDialog.Detail)
    dialog.setDirectory(QDir.homePath())

    if dialog.exec_():
        paths = dialog.selectedFiles()
        assert len(paths) == 1
        path = Path(paths[0])
        return path
コード例 #2
0
    def createEditor(self, parent: QWidget, option: QStyleOptionViewItem,
                     index: QModelIndex) -> QWidget:
        view: ImagesTableView = option.widget
        model: ImagesTableModel = view.model()
        path: str = model.data(index, Qt.EditRole)
        path = Path(path)
        abspath = model.basepath / Image.images_dir / path

        dialog = QFileDialog(parent.window(), Qt.Dialog)
        dialog.setWindowModality(Qt.ApplicationModal)
        dialog.setMinimumWidth(800)
        dialog.setMinimumHeight(600)
        dialog.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Dialog)
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.setViewMode(QFileDialog.Detail)
        dialog.setDirectory(str(abspath.parent))
        dialog.selectFile(str(abspath.name))
        dialog.setLabelText(QFileDialog.LookIn, "Rename image file")

        return dialog