gpt4 book ai didi

Python PyQt5 - 检测垂直标题项的点击(QTableWidget)

转载 作者:太空宇宙 更新时间:2023-11-03 19:54:24 25 4
gpt4 key购买 nike

我想知道是否有任何方法可以检测垂直标题项(行标题)上的鼠标单击。我可以检测对表格单元格的点击,没有问题,但似乎没有任何方法可以检测对标题项的点击。

self.w3.WorkerTab.clicked.connect(self.putNameInComboBoxFromTableClick)
self.w3.WorkerTab.doubleClicked.connect(self.putDoubleClickDataInSpaces)

我将正常给定的标题(数字)更改为员工姓名(行)和工作日(列)。现在(使用下面的代码),只需单击一行中的任何项目,就会检测到行标题内容并将其放入组合框中。双击后,它会再次检测到员工并打开另一个窗口来自定义员工。

def putNameInComboBoxFromTableClick(self, item):
selectedName = self.w3.WorkerTab.verticalHeaderItem(item.row())
NameMA = selectedName.text()
indexMA = self.w3.chooseWorkerBox.findText(NameMA)
self.w3.chooseWorkerBox.setCurrentIndex(indexMA)

def putDoubleClickDataInSpaces(self, item):
selectedName = self.w3.WorkerTab.verticalHeaderItem(item.row())
NameMA = selectedName.text()
AZ = "AZ"
with open(self.database) as mb_json:
data = json.load(mb_json)
# Festlegung der Abteilung
for key1 in data:
for key2 in data[key1]:
if key2 == NameMA:
self.w4.NameText.setText(NameMA)
self.w4.MoText.setCurrentText(data[key1][key2][AZ]["Mo"])
self.w4.DiText.setCurrentText(data[key1][key2][AZ]["Di"])
self.w4.MiText.setCurrentText(data[key1][key2][AZ]["Mi"])
self.w4.DoText.setCurrentText(data[key1][key2][AZ]["Do"])
self.w4.FrText.setCurrentText(data[key1][key2][AZ]["Fr"])
self.w4.SaText.setCurrentText(data[key1][key2][AZ]["Sa"])
self.w4.OeText.setText(key1)
self.w4.show()
self.w3.close()

最佳答案

我自己找到了解决方案:

self.w3.WorkerTab.verticalHeader().sectionClicked.connect(self.putNameInComboBoxFromTableClick)
self.w3.WorkerTab.verticalHeader().sectionDoubleClicked.connect(self.putDoubleClickDataInSpaces)

并编辑了其他代码:

def putNameInComboBoxFromTableClick(self):
row = self.w3.WorkerTab.currentItem().row()
selectedName = self.w3.WorkerTab.verticalHeaderItem(row)
NameMA = selectedName.text()
indexMA = self.w3.chooseWorkerBox.findText(NameMA)
self.w3.chooseWorkerBox.setCurrentIndex(indexMA)

def putDoubleClickDataInSpaces(self):
row = self.w3.WorkerTab.currentItem().row()
selectedName = self.w3.WorkerTab.verticalHeaderItem(row)
NameMA = selectedName.text()
AZ = "AZ"
with open(self.database) as mb_json:
data = json.load(mb_json)
# Festlegung der Abteilung
for key1 in data:
for key2 in data[key1]:
if key2 == NameMA:
self.w4.NameText.setText(NameMA)
self.w4.MoText.setCurrentText(data[key1][key2][AZ]["Mo"])
self.w4.DiText.setCurrentText(data[key1][key2][AZ]["Di"])
self.w4.MiText.setCurrentText(data[key1][key2][AZ]["Mi"])
self.w4.DoText.setCurrentText(data[key1][key2][AZ]["Do"])
self.w4.FrText.setCurrentText(data[key1][key2][AZ]["Fr"])
self.w4.SaText.setCurrentText(data[key1][key2][AZ]["Sa"])
self.w4.OeText.setText(key1)
self.w4.show()
self.w3.close()

关于Python PyQt5 - 检测垂直标题项的点击(QTableWidget),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59627752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com