[英]how to get the row number of an item in the qlistwidget using Pyqt5 in python
How to get the row number of each item in the QlistWidget ia able to get the text of the item but not the row number. 如何获取QlistWidget中每个项目的行号,从而能够获取项目的文本,但不能获取行号。
the expected result : 预期结果:
i don't know how to return the row number i tried the index but it return a wrong result. 我不知道如何返回行号,但尝试返回索引,但返回错误的结果。
I think this is the line that must changed: 我认为这是必须更改的行:
print("current row ==> {} \n checkpath Displayed Path => {}".format(index,self.fullPath))
where index is used in enumarate . 其中index用于表示enumarate 。
def checkPath(self,folder): # Funtion to check the given path for the wanted extension (Files)
try:
directory=folder
whichChecked=""
for root,dirs,files in os.walk(directory):
for index,filename in enumerate(files):
if len(self.lineEdit_Ext.text())>0:
self.lineEdit_Ext.setStyleSheet("background-color:white")
self.lineEdit_Ext.setPlaceholderText("Enter The Filetype Extention Here")
if filename.endswith(self.lineEdit_Ext.text()):
fullPath=os.path.join(root,filename)
print(fullPath)
self.fileList.append(fullPath)
elif self.rdBtn_docx.isChecked() and filename.endswith("docx") or filename.endswith("doc") :
self.fullPath=os.path.join(root,filename)
index = +1
print("current row ==> {} \n checkpath Displayed Path => {}".format(index,self.fullPath))
print("=========================================")
self.fileList.append(self.fullPath)
whichChecked="docx - doc Ext was Selected"
if len(self.fileList) > 0:
self.lineEdit_Ext.setStyleSheet("bacground-color:white;")
self.lineEdit_Ext.setPlaceholderText("{0}".format(whichChecked))
else:
self.lineEdit_Ext.setStyleSheet("background-color:Red")
self.lineEdit_Ext.setPlaceholderText("No Ext is Specified")
self.ListFilesInViewer(self.fileList) # add the list into the listWidgetPDFlist
return folder
except Exception as e:
print("this error occure {0}".format(e))
QListWidget.currentRow()
QListWidget.currentRow()
Return type: PySide.QtCore.int
返回类型:PySide.QtCore.int
This property holds the row of the current item..
此属性保存当前项目的行。
. 。 .
。 .
。
def FileListSelected(self):
""" Function to select the desired file from the list in the left pane """
itemNumber = self.listWidgetPDFlist.currentRow() # +++
Item = self.listWidgetPDFlist.currentItem().text()
print("this is the SELECTED file==>{}".format(Item))
print("this is the itemNumber ==>{}".format(itemNumber)) # +++
. 。 .
。 .
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.