繁体   English   中英

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

[英]how to get the row number of an item in the qlistwidget using Pyqt5 in python

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

预期结果:

  • 当前行==> 1
  • checkpath显示的路径=> C:/用户/测试/下载\\ cv.docx

我不知道如何返回行号,但尝试返回索引,但返回错误的结果。

我认为这是必须更改的行:

                print("current row ==> {} \n checkpath  Displayed Path => {}".format(index,self.fullPath))

其中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()

返回类型:PySide.QtCore.int

此属性保存当前项目的行。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM