Answer the question
In order to leave comments, you need to log in
PyQt emitting multiple signals on QTableWidget?
Hello. I'm not an expert in PyQt, I'm just starting to learn. And I encountered extremely strange behavior of signals that cannot be overcome.
There is a QTableWidget widget with a certain hierarchy, which is constantly refilled depending on user actions (to be more precise, search is implemented using QLineEdit). Table elements are clickable. I connect Double-click like this:
self.ui.tree.itemDoubleClicked.connect(self.connect)
item = self.ui.tree.currentItem()
self.ui.tree.blockSignal(True)
<перезаписываем ...>
self.ui.tree.blockSignal(False)
Answer the question
In order to leave comments, you need to log in
Here, I threw it, without duplicate signals, with refilling, etc.
import sys
from PySide2.QtWidgets import QApplication, QTableWidget, QTableWidgetItem
class Main(QTableWidget):
def __init__(self):
super(Main, self).__init__()
self.setRowCount(10)
self.setColumnCount(5)
self.itemDoubleClicked.connect(self.__on_item_double_click)
self.setEditTriggers(self.EditKeyPressed | self.AnyKeyPressed)
self.filling_count = 0
self.refill()
def __on_item_double_click(self, item: QTableWidgetItem):
print(f"row:{item.row()} col:{item.column()} item: {item}")
self.refill()
def refill(self):
self.filling_count += 1
for row in range(self.rowCount()):
for col in range(self.columnCount()):
item = QTableWidgetItem(
f"row:{row + 1} col:{col + 1} filled: {self.filling_count}"
)
self.setItem(row, col, item)
self.resizeColumnsToContents()
if __name__ == "__main__":
app = QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question