Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PySide2 import QtCore, QtGui, QtWidgets
- import os
- file = 'template'
- path_dir = r'D:templates'
- class Ui_Form(object):
- def setupUi(self, Form):
- Form.setObjectName("Form")
- Form.resize(1266, 798)
- self.treeView = QtWidgets.QTreeView(Form)
- self.treeView.setGeometry(QtCore.QRect(40, 70, 611, 241))
- self.treeView.setObjectName("treeView")
- #-------------
- # ? self.treeView.QFileSystemModel.directoryLoaded('D:testqt')
- #-------------
- self.pushButton = QtWidgets.QPushButton(Form)
- self.pushButton.setGeometry(QtCore.QRect(670, 70, 131, 41))
- self.pushButton.setObjectName("pushButton")
- self.pushButton.clicked.connect(self.save_file)
- self.label = QtWidgets.QLabel(Form)
- self.label.setGeometry(QtCore.QRect(40, 42, 541, 21))
- self.label.setObjectName("label")
- self.retranslateUi(Form)
- QtCore.QMetaObject.connectSlotsByName(Form)
- def retranslateUi(self, Form):
- Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1))
- self.pushButton.setText(QtWidgets.QApplication.translate("Form", "PushButton", None, -1))
- self.label.setText(QtWidgets.QApplication.translate("Form", "TextLabel", None, -1))
- def save_file(self):
- print('File', file , 'saved in: ' , path_dir, '!')
- class Widget(QtWidgets.QWidget, Ui_Form):
- def __init__(self, parent=None):
- super(Widget, self).__init__(parent)
- self.setupUi(self)
- self.resize(1266, 798)
- layout = QtWidgets.QHBoxLayout(self)
- # layout.addWidget(self.label)
- # layout.addWidget(self.treeView)
- # layout.addWidget(self.pushButton)
- self.model = QtWidgets.QFileSystemModel()
- self.model.setFilter(QtCore.QDir.AllEntries | QtCore.QDir.Hidden | QtCore.QDir.NoDot)
- self.path = os.path.expanduser('D:') # <-- ('D:/test/qt')
- self.parentIndex = self.model.setRootPath(self.path)
- self.treeView.setModel(self.model)
- self.treeView.setRootIndex(self.model.index(self.path))
- self.model.directoryLoaded.connect(self._loaded)
- self.dirictory = QtWidgets.QDirModel()
- self.dirictory.index(self.path)
- self.dirictory.filePath(self.dirictory.index(self.path))
- print(self.dirictory.filePath(self.dirictory.index(self.path)))
- def _loaded(self, path):
- print('_loaded', self.path)
- print('++loaded', self.dirictory.filePath(self.dirictory.index(self.path)))
- if __name__ == "__main__":
- import sys
- app = QtWidgets.QApplication(sys.argv)
- # Form = QtWidgets.QWidget()
- # ui = Ui_Form()
- # ui.setupUi(Form)
- # Form.show()
- w = Widget()
- w.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement