Pyside6: Get a signal from a QLineEdit in a QTableWidget cell

32 views Asked by At

I have a QTableWidget with a column containing QLineEdit widgets. I want to get a signal from the QLineEdit such as textEdited, but I can't figure out how to connect to it. I can connect to a QTableWidgetItem using tableWidget.itemClicked.connect(self.TestCellClick), but as soon as I put a QLineEdit widget in a cell, I can't get a signal from it. Here's what I'm doing so far, but the line "lineEdit.textEdited[str].connect(self.TestCellLineEdited)" seems to have no effect.

import sys
from PySide6 import QtWidgets as QtWidgets
from PySide6.QtCore import QRect
from PySide6.QtWidgets import (QTableWidget, QTableWidgetItem)

class Ui_Form(object):
    def setupUi(self, Form):
        Form.resize(400, 300)
        self.tableWidget = QTableWidget(Form)
        self.tableWidget.setColumnCount(2)
        self.tableWidget.setRowCount(4)
        self.tableWidget.setGeometry(QRect(50, 60, 256, 192))
        self.tableWidget.setHorizontalHeaderLabels(['Parameters', 'Values'])

class MainWindow(QtWidgets.QMainWindow, Ui_Form):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.ui.tableWidget.itemClicked.connect(self.TestCellClick)

        for row in range(4):
            item = QTableWidgetItem("Label{0}".format(str(row)))
            self.ui.tableWidget.setItem(row, 0, item)

            lineEdit = QtWidgets.QLineEdit()
            lineEdit.setText("Hello")
            lineEdit.textEdited[str].connect(self.TestCellLineEdited)
            self.ui.tableWidget.setCellWidget(row, 1, lineEdit)

    def TestCellClick(self, item: QTableWidgetItem):
        if item.column() == 0:
            return
        pass

    def TestCellLineEdited(self, item: str):
        if item == "Hello":
            print ("found")
        pass
0

There are 0 answers