久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <small id='Ns7bw'></small><noframes id='Ns7bw'>

      <tfoot id='Ns7bw'></tfoot>

      <legend id='Ns7bw'><style id='Ns7bw'><dir id='Ns7bw'><q id='Ns7bw'></q></dir></style></legend>
      <i id='Ns7bw'><tr id='Ns7bw'><dt id='Ns7bw'><q id='Ns7bw'><span id='Ns7bw'><b id='Ns7bw'><form id='Ns7bw'><ins id='Ns7bw'></ins><ul id='Ns7bw'></ul><sub id='Ns7bw'></sub></form><legend id='Ns7bw'></legend><bdo id='Ns7bw'><pre id='Ns7bw'><center id='Ns7bw'></center></pre></bdo></b><th id='Ns7bw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ns7bw'><tfoot id='Ns7bw'></tfoot><dl id='Ns7bw'><fieldset id='Ns7bw'></fieldset></dl></div>
      • <bdo id='Ns7bw'></bdo><ul id='Ns7bw'></ul>
      1. 如何在樹視圖中顯示父目錄?

        How to display parent directory in tree view?(如何在樹視圖中顯示父目錄?)

          1. <i id='gSEKy'><tr id='gSEKy'><dt id='gSEKy'><q id='gSEKy'><span id='gSEKy'><b id='gSEKy'><form id='gSEKy'><ins id='gSEKy'></ins><ul id='gSEKy'></ul><sub id='gSEKy'></sub></form><legend id='gSEKy'></legend><bdo id='gSEKy'><pre id='gSEKy'><center id='gSEKy'></center></pre></bdo></b><th id='gSEKy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gSEKy'><tfoot id='gSEKy'></tfoot><dl id='gSEKy'><fieldset id='gSEKy'></fieldset></dl></div>

              <tfoot id='gSEKy'></tfoot>

                <small id='gSEKy'></small><noframes id='gSEKy'>

                  <bdo id='gSEKy'></bdo><ul id='gSEKy'></ul>
                    <tbody id='gSEKy'></tbody>
                  <legend id='gSEKy'><style id='gSEKy'><dir id='gSEKy'><q id='gSEKy'></q></dir></style></legend>

                  本文介紹了如何在樹視圖中顯示父目錄?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  在我的應(yīng)用程序中,我有一個 QTreeview.我有一個名為test"的文件夾,其中包含許多子文件夾.樹形視圖只顯示子文件夾而不是它自己的測試文件夾!

                  In my application I have a QTreeview. I have a folder named "test" that contains many subfolders. The treeview only shows the subfolders not the test forlder it self!

                  def create_treeview(self):
                      self.treeView = QTreeView()
                      self.treeView.setMinimumSize(QSize(250, 0))
                      self.treeView.setMaximumSize(QSize(250, 16777215))
                      self.treeView.setObjectName("treeView")
                  
                      self.dirModel = QFileSystemModel()
                      self.dirModel.setRootPath(QDir.rootPath())
                      self.dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
                  
                      self.treeView.setModel(self.dirModel)
                      self.treeView.setRootIndex(self.dirModel.index("/home/data/test"))
                      self.treeView.setHeaderHidden(True)
                      self.treeView.clicked.connect(self.tree_click)
                      return self.treeView
                  

                  推薦答案

                  QTreeView 的rootIndex 被隱藏所以不顯示.一種可能的解決方案是傳遞路徑的父級并使用 QSortFilterProxyModel 隱藏其他目錄和文件.

                  The rootIndex of the QTreeView is hidden so it is not shown. One possible solution is to pass the parent of the path and use a QSortFilterProxyModel to hide the other directories and files.

                  import os
                  
                  from PyQt5.QtCore import pyqtSlot, QDir, QModelIndex, QSize, QSortFilterProxyModel
                  from PyQt5.QtWidgets import QApplication, QFileSystemModel, QMainWindow, QTreeView
                  
                  
                  class ProxyModel(QSortFilterProxyModel):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self._root_path = ""
                  
                      def filterAcceptsRow(self, source_row, source_parent):
                          source_model = self.sourceModel()
                          if self._root_path and isinstance(source_model, QFileSystemModel):
                              root_index = source_model.index(self._root_path).parent()
                              if root_index == source_parent:
                                  index = source_model.index(source_row, 0, source_parent)
                                  return index.data(QFileSystemModel.FilePathRole) == self._root_path
                          return True
                  
                      @property
                      def root_path(self):
                          return self._root_path
                  
                      @root_path.setter
                      def root_path(self, p):
                          self._root_path = p
                          self.invalidateFilter()
                  
                  
                  class MainWindow(QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.create_treeview()
                          self.setCentralWidget(self.treeView)
                  
                      def create_treeview(self):
                  
                          path = "/home/data/test"
                  
                          self.treeView = QTreeView()
                          self.treeView.setMinimumSize(QSize(250, 0))
                          self.treeView.setMaximumSize(QSize(250, 16777215))
                          self.treeView.setObjectName("treeView")
                  
                          self.dirModel = QFileSystemModel()
                          self.dirModel.setRootPath(QDir.rootPath())
                          self.dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
                  
                          root_index = self.dirModel.index(path).parent()
                  
                          self.proxy = ProxyModel(self.dirModel)
                          self.proxy.setSourceModel(self.dirModel)
                          self.proxy.root_path = path
                  
                          self.treeView.setModel(self.proxy)
                  
                          proxy_root_index = self.proxy.mapFromSource(root_index)
                          self.treeView.setRootIndex(proxy_root_index)
                  
                          self.treeView.setHeaderHidden(True)
                          self.treeView.clicked.connect(self.tree_click)
                  
                      @pyqtSlot(QModelIndex)
                      def tree_click(self, index):
                          ix = self.proxy.mapToSource(index)
                          print(
                              ix.data(QFileSystemModel.FilePathRole),
                              ix.data(QFileSystemModel.FileNameRole),
                          )
                  
                  
                  if __name__ == "__main__":
                      import sys
                  
                      app = QApplication(sys.argv)
                      w = MainWindow()
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關(guān)于如何在樹視圖中顯示父目錄?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進(jìn)度條?)
                    • <bdo id='WKheR'></bdo><ul id='WKheR'></ul>
                      <legend id='WKheR'><style id='WKheR'><dir id='WKheR'><q id='WKheR'></q></dir></style></legend>
                          <tbody id='WKheR'></tbody>

                        <i id='WKheR'><tr id='WKheR'><dt id='WKheR'><q id='WKheR'><span id='WKheR'><b id='WKheR'><form id='WKheR'><ins id='WKheR'></ins><ul id='WKheR'></ul><sub id='WKheR'></sub></form><legend id='WKheR'></legend><bdo id='WKheR'><pre id='WKheR'><center id='WKheR'></center></pre></bdo></b><th id='WKheR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WKheR'><tfoot id='WKheR'></tfoot><dl id='WKheR'><fieldset id='WKheR'></fieldset></dl></div>
                            <tfoot id='WKheR'></tfoot>
                          1. <small id='WKheR'></small><noframes id='WKheR'>

                            主站蜘蛛池模板: 日韩不卡一区二区三区 | 高清久久久 | 羞羞视频免费观看 | 亚洲视频免费观看 | 久久国产精品久久国产精品 | 密室大逃脱第六季大神版在线观看 | 国产一区二区激情视频 | 国产激情视频网址 | 国产精品免费大片 | 精品欧美一区免费观看α√ | 黄色成人在线 | 在线观看中文字幕av | 黑人久久久 | 亚洲在线一区 | 久久久蜜臀国产一区二区 | 日韩高清黄色 | 亚洲成人免费av | 精品欧美黑人一区二区三区 | 欧美日韩精品一区二区三区四区 | 在线成人一区 | 成人三级网址 | 日韩三区在线 | 午夜精品久久久久久久99黑人 | 精品粉嫩aⅴ一区二区三区四区 | 国产精品免费一区二区三区四区 | 日本a v在线播放 | 国产精品99久久久久久动医院 | 久草在线 | 成人久久网 | 日韩精品一区二区三区在线播放 | 亚洲第一av | 亚洲国产精品精华素 | 免费看片国产 | 日本久久久一区二区三区 | 日韩在线视频播放 | 成人欧美一区二区三区黑人孕妇 | 国产成人免费 | 国产精品爱久久久久久久 | 国产日产欧产精品精品推荐蛮挑 | 午夜精品 | 久久大全 |