Как получить номер строки элемента в qlistwidget, используя Pyqt5 в Python - PullRequest
0 голосов
/ 06 июля 2018

Как получить номер строки каждого элемента в 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 голосов
/ 06 июля 2018

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)) # +++

. , .

enter image description here

...