python - PyQt中,树形结构QtreeView中,单击节点获取其绝对路径
PHPz
PHPz 2017-04-18 10:10:06
0
1
931
PHPz
PHPz

学习是最好的投资!

reply all(1)
Peter_Zhu

I am also using pyqt recently, 233~
I don’t know what your file refers to, but if your file and your py file are in the same directory, then this will be easy to handle.

The code below is just an outline

  • First you get the file name of the node you clicked

fileName = self.currentRow().text()    
# 不知道tree是不是这样,反正QListWidget获取当前节点就是currentRow()
  • Get the absolute path, and then concatenate it with the file name to get the absolute path of the file

import os
# 获取当前文件的绝对路径,也就是你的py文件的当前绝对路径
abDir = os.path.abspath(os.path.join(os.path.dirname(__file__))).replace('\','/')
fileDir = abDir + fileName

If it can solve the problem, please adopt it~~~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!