python - 我如何连接一列QTableWidget

标签 python pyqt pyqt5

当用户更改其值时,我只需要连接一列,因为如果您使用

self.Table.cellChanged() 如果数据库中的所有值发生更改,它将发送一个信号

示例(查看#Comment往下)

from PyQt5 import QtWidgets, QtCore, QtGui

class SalesMan(object):

    def __init__(self, window):
        window.resize(650, 600)
        window.setWindowTitle('Example')
        self.Window = window
        self.Barcode = QtWidgets.QLineEdit(window)
        self.Table = QtWidgets.QTableWidget(100, 6, window)
        self.Table.setGeometry(0, 0, 650, 600)
        self.Table.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.Table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
        # need Call if column(0,1) Changed, Not All Column
        self.Table.cellChanged.connect(self.Ex)

    def Ex(self):
        print('Some')


if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    form = QtWidgets.QMainWindow()
    d = SalesMan(form)
    form.show()
    sys.exit(app.exec_())

最佳答案

您要做的就是根据通过信号传输的参数过滤列:

class SalesMan(object):
    def __init__(self, window):
        window.resize(650, 600)
        window.setWindowTitle("Example")
        self.Window = window
        self.Barcode = QtWidgets.QLineEdit(window)
        self.Table = QtWidgets.QTableWidget(100, 6, window)
        self.Table.setGeometry(0, 0, 650, 600)
        self.Table.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.Table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
        # need Call if column(0,1) Changed, Not All Column
        self.Table.cellChanged.connect(self.Ex)

    <b>def Ex(self, row, column):
        if column == 0:
            print("Some", row, column)</b>

关于python - 我如何连接一列QTableWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60091616/

相关文章:

python - 如何传输信号来检测按钮是否被单击?

python - 克隆存储库后 Django 无法迁移

python - 更新 PyQt 小部件

python - PyQt:具有撤消和重做操作的 QTableWidget

python - C :/Program is not recognized . ..与 pyuic5 相关

python - QTcpSocket read 未发出

python - 使用 .ui 表单 Autowiring 时 QPushButton.clicked() 会触发两次

python - 如何使用 Python 将日期时间属性添加到 JPG 文件中,以便在 Google Photos 中正确建立索引?

python - 异步运行时错误 : Event Loop is Closed

python - XPath 从两个子文本获取父元素