我有以下代码片段:
self.model = QFileSystemModel()
self.model.setRootPath('')
self.tree = QTreeView()
self.tree.setModel(self.model)
self.tree.setAnimated(False)
self.tree.setIndentation(20)
self.tree.setSortingEnabled(True)
self.tree.setWindowTitle("Directory Viewer")
self.tree.resize(323, 300)
self.tree.show()
这将打开一个窗口来管理目录(文件)。但在我的MainApp UI之外(因此,会打开一个新窗口),我想在其中嵌入此外部窗口,如下所示:
class MainApp(QMainWindow):
"""This is the class of the MainApp GUI system"""
def __init__(self):
"""Constructor method"""
super().__init__()
self.initUI()
def initUI(self):
"""This method creates our GUI"""
# Box Layout to organize our GUI
# labels
types1 = QLabel('Label', self)
types1.resize(170, 20)
types1.move(1470, 580)
self.model = QFileSystemModel()
self.model.setRootPath('')
self.tree = QTreeView()
self.tree.setModel(self.model)
self.tree.setAnimated(False)
self.tree.setIndentation(20)
self.tree.setSortingEnabled(True)
self.tree.setWindowTitle("Directory Viewer")
self.tree.resize(323, 300)
self.tree.show()
self.setGeometry(50, 50, 1800, 950)
self.setFixedSize(self.size())
self.centering()
self.setWindowTitle('MainApp')
self.setWindowIcon(QIcon('image/logo.png'))
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainApp()
sys.exit(app.exec_())
self.show()
如何将此窗口嵌入MainApp UI,作为主要图形应用程序的一部分,如小部件?
谢谢