【发布时间】:2018-11-27 04:13:40
【问题描述】:
我有一个代码在 QlistWidget 中显示项目(文件),用户点击项目,系统会显示其内容。
示例:
- C:\Users\test\Desktop\New Microsoft Word Document.docx ==> 第 0 行
- C:\Users\test\Desktop\test_arabic.docx ==> 第 1 行
当尝试打印结果时,系统显示正确的行号但路径错误,无论您接下来选择什么,它都会显示第一个选择的文件路径
代码:
def FileListSelected(self): # Function to select the desired file from the list in the left pane
ListIterator=range(self.listWidgetPDFlist.count() -1)
for index in ListIterator:
p = pathlib.Path(self.fullPath)
print(" FILE SELECTED this is P==>{}".format(p))
oneDir = os.path.join(*p.parts[:-2])
print("FILE SELECTED this is oneDir==>{}".format(oneDir))
Item= oneDir + "\\" + self.listWidgetPDFlist.selectedItems()[index].text()
print("FILE SELECTED this is the cuurent Item =={}".format(Item))
print("current row = {}".format(self.listWidgetPDFlist.currentRow()))
self.mouseHover()
return Item
【问题讨论】:
标签: python for-loop pyqt qlistwidget