1

Im dealing with a problem when using PyQt5, i already made a QTableWidget which displays a DataFrame i prevously made in pandas (from a spreadsheet).

What im trying unsuccesfully to do is: Get the text from the cell that the user double-clicks so i can use that information to build up a new Widget based on choice made.

What i've learned is that i first need to connect the double-click to a function, but i cant continue afterwards:

my connection on my QTableWidget goes as follows:

(Under my MainWindow Widget)

self.tableView.cellDoubleClicked.connect(self.expandShipments)

"Afterwards i declare the function to which this signal connects (expandShipments)"

def expandShipments(self):

 *** code i need to get doubleClicked cell text ***

I'd really appreciate a hand with this case.

Thanks. Kudos

EDIT: This is the way my table is populated.

QTableWidget.

def loadFile(self):
    fileName='C:/Users/310287757/Desktop/JLG/Programming/tstBIGDF.xlsx'
    df = pandas.read_excel(fileName, sheetname='MAIN', header=0)  # read file and set header row
    df= df.loc[df['Name Opp'] == self.comboProy.currentText()]
    self.tableView.setColumnCount(len(df.columns))
    self.tableView.setRowCount(len(df.index))
    tags=[]
    for ele in list(df.columns.values):
        tags.append(ele)

    self.tableView.setHorizontalHeaderLabels(tags)
    for i in range(len(df.index)):
        for j in range(len(df.columns)):
            self.tableView.setItem(i, j, QTableWidgetItem(str(df.iat[i, j])))

    self.tableView.resizeColumnsToContents()
    self.tableView.resizeRowsToContents()
    PPen = df['Pending amount'].values.sum()
    PTot = df['total item amount'].values.sum()
    PP=("Pendiente por facturar: U$S %.2f"% PPen)
    PT=("Total: U$S %.2f" % PTot)
    self.lblPEND.setText(PP)
    self.lblTOTAL.setText(PT)

    del df,fileName,tags
Jay Lopez
  • 71
  • 1
  • 9

1 Answers1

3

The cellDoubleClicked signal sends the row and column. So your code should look like this:

self.tableView.cellDoubleClicked.connect(self.expandShipments)
...

def expandShipments(self, row, column):
    item = self.tableView.item(row, column)
    print(item.text())
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • 2
    Merci Beaucoup! Btw i know this case might sound a lil dummy, but i find Pyqt module documentation hard to understand sometimes. kudos – Jay Lopez Oct 13 '17 at 22:42
  • 1
    @JayLopez Use the documentation of Qt, if you know the minimum of C ++ you will understand correctly. :P – eyllanesc Oct 13 '17 at 22:51