如何在python中使用Pyqt5获取qlistwidget中项目的行号

如何在python中使用Pyqt5获取qlistwidget中项目的行号,python,pyqt5,row-number,Python,Pyqt5,Row Number,如何获取QlistWidget中每个项目的行号i a能够获取项目的文本,但不能获取行号 预期结果: 当前行==>1 检查路径显示路径=>C:/Users/test/Downloads\cv.docx 我不知道如何返回行号,我尝试了索引,但它返回了错误的结果。 我认为这是必须改变的路线: print("current row ==> {} \n checkpath Displayed Path => {}".format(index,self.fu

如何获取QlistWidget中每个项目的行号i a能够获取项目的文本,但不能获取行号

预期结果:

  • 当前行==>1
  • 检查路径显示路径=>C:/Users/test/Downloads\cv.docx
我不知道如何返回行号,我尝试了索引,但它返回了错误的结果。

我认为这是必须改变的路线:

                print("current row ==> {} \n checkpath  Displayed Path => {}".format(index,self.fullPath))
其中,索引用于枚举

代码: QListWidget.currentRow()

返回类型:PySide.QtCore.int

此属性保存当前项的行


谢谢您的回答。但是我想要的不是返回所选项目的行号,我想要的是,一旦用户选择了路径并且QlistWidget显示了项目..我需要返回每个项目及其行号。。。。因为在这之后,当用户选择一个项目时,我需要比较行号。因此,我认为该语句必须在CheckPath函数中执行,而不是在FileListSelected函数中执行。所选项目的行号-->>>itemNumbermy问题与所选项目无关。。。我需要的是打印QlistWidget中的所有项目及其行号。
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))
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)) # +++