pyqt tableWIdge某个单元格点击打开QFileDialog
时间: 2023-10-09 13:07:49 浏览: 129
可以使用如下代码实现:
```
from PyQt5.QtWidgets import QApplication, QFileDialog, QTableWidget, QTableWidgetItem
def open_file_dialog():
file_names, _ = QFileDialog.getOpenFileNames(None, "Open File", "", "All Files(*);;Text Files(*.txt)")
if file_names:
print("Selected Files:", file_names)
table_widget = QTableWidget()
table_widget.setRowCount(2)
table_widget.setColumnCount(2)
item = QTableWidgetItem("Click here to open file dialog")
table_widget.setItem(0, 0, item)
item = QTableWidgetItem("Another cell")
table_widget.setItem(0, 1, item)
item = QTableWidgetItem("Yet another cell")
table_widget.setItem(1, 0, item)
item = QTableWidgetItem("Final cell")
table_widget.setItem(1, 1, item)
table_widget.cellClicked.connect(lambda row, column: open_file_dialog() if row == 0 and column == 0 else None)
```
阅读全文