pyside 获取QTableWidget的双击的行列
时间: 2024-10-29 15:05:08 浏览: 157
在PySide中,如果你想要监听`QTableWidget`的双击事件并获取点击的行和列,你可以通过继承`QTableWidget`并在其中覆盖`mouseDoubleClickEvent`方法来实现。以下是一个简单的例子:
```python
from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidget
from PySide6.QtCore import Qt
class CustomTable(QTableWidget):
def __init__(self, parent=None):
super().__init__(parent)
def mouseDoubleClickEvent(self, event):
row = self.indexAt(event.pos()).row()
column = self.indexAt(event.pos()).column()
print(f"双击了第{row}行,第{column}列")
# 这里可以添加你想要处理双击的具体操作
# 创建窗口和表格
app = QApplication([])
window = QMainWindow()
table = CustomTable(window)
# 设置表格大小和其他属性
table.setRowCount(10) # 设置10行
table.setColumnCount(5) # 设置5列
table.doubleClicked.connect(table.cellDoubleClicked) # 监听双击事件
# 显示表格
window.show()
# 运行应用程序
app.exec_()
```
在这个例子中,当你在`QTableWidget`上双击时,会打印出双击的位置信息。记得将这部分代码替换为你实际的需求。
阅读全文
相关推荐


















