cellDoubleClicked 文本 python [英] cellDoubleClicked text python
问题描述
我在使用 PyQt5 时遇到了一个问题,我已经制作了一个 QTableWidget,它显示了我之前在 Pandas 中制作的 DataFrame(来自电子表格).
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:
我在 QTableWidget 上的连接如下:
my connection on my QTableWidget goes as follows:
(在我的 MainWindow 小部件下)
(Under my MainWindow Widget)
self.tableView.cellDoubleClicked.connect(self.expandShipments)
然后我声明这个信号连接的函数(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.
谢谢.点赞
这是我的表格填充方式.
This is the way my table is populated.
QTableWidget.
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
推荐答案
cellDoubleClicked 信号发送行和列.所以你的代码应该是这样的:
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())
这篇关于cellDoubleClicked 文本 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!