Please help me understand the next problem.
There is an application where the QTreeView widget with the tree structure of files is located on the left and the QTextEdit text field on the right.
How to make it so that if you double-click with the left mouse button on, say, a text file, it would open a text field?
In other words, I need to get the absolute path to the file by double clicking on it. Tell me how to do it.
import sys from PyQt5.QtWidgets import (QApplication, QWidget, QSplitter, QTreeView, QTextEdit, QFileSystemModel, QVBoxLayout) from PyQt5.QtCore import QDir import os class MyWidget(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setWindowTitle('Direct tree') self.resize(600, 400) self.vbox = QVBoxLayout() self.splitter = QSplitter() self.model = QFileSystemModel() self.model.setRootPath(QDir.rootPath()) self.tree = QTreeView() self.tree.setModel(self.model) self.tree.setRootIndex(self.model.index(os.getcwd())) self.textEdit = QTextEdit() self.splitter.addWidget(self.tree) self.splitter.addWidget(self.textEdit) self.splitter.setSizes([50, 200]) self.vbox.addWidget(self.splitter) self.setLayout(self.vbox) self.tree.setAnimated(False) self.tree.setIndentation(20) self.tree.setSortingEnabled(True) if __name__ == "__main__": app = QApplication(sys.argv) win = MyWidget() win.show() sys.exit(app.exec_()) 
