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

时间:2018-07-06 07:24:25

标签: python pyqt5 row-number

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

预期结果:

  • 当前行==> 1
  • checkpath显示的路径=> C:/ Users / test / Downloads \ 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))

1 个答案:

答案 0 :(得分:0)

  

QListWidget.currentRow()

     

返回类型:PySide.QtCore.int

     

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

。 。 。

try {
    android.content.pm.PackageInfo info = getPackageManager().getPackageInfo(
            "com.apps.sonictonic",
            android.content.pm.PackageManager.GET_SIGNATURES);
    for (android.content.pm.Signature signature : info.signatures) {
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        android.util.Log.d("KeyHash", "KeyHash:" + android.util.Base64.encodeToString(md.digest(),
                android.util.Base64.DEFAULT));

    }
} catch (android.content.pm.PackageManager.NameNotFoundException e) {

} catch (java.security.NoSuchAlgorithmException e) {

}

。 。

enter image description here