'Show MyComputer in PyQt5 Tree View

I have coded out a small application using PyQt5 . The application gives a tree view of all folders in the computer :

import sys
from PyQt5.QtWidgets import (
    QMainWindow, QApplication,
    QHBoxLayout,QWidget,
     QVBoxLayout,QFileSystemModel, QTreeView, QLineEdit
)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        layout = QHBoxLayout()
        application = App()
        layout.addWidget(application)
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
    
class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    
    def initUI(self):
        self.model = QFileSystemModel()
        self.model.setNameFilters([''])
        self.model.setNameFilterDisables(0)
        self.model.setRootPath('')
        self.tree = QTreeView()
        self.tree.setModel(self.model)
        self.tree.setAnimated(False)
        self.tree.setSortingEnabled(True)
        self.setLayout(layout)

app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec()

Usually, when we open a file browser, the file browser directly shows "My Computer" and in particular the Desktop:

enter image description here

However, my application does not directly show "My Computer" and folders in it:

enter image description here

In particular, it does not show Desktop directly. In order to get to the desktop, one has to expand the C drive:

enter image description here

What I want is to make the desktop separately available (i.e. not just under the C drive but also available as a separate root just like all the drives).

To resolve this problem, I tried to play with the myComputer method by adding lines like:

self.model.myComputer(0)

(Documentation: https://doc.qt.io/qt-5/qfilesystemmodel.html#myComputer). This does not give me anything and I am in general confused about what they mean by "role" .



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source