R
R
runcode2018-11-19 22:29:35
Python
runcode, 2018-11-19 22:29:35

Why clone?

I set a timer to update the table, when you click on the checkbox, in the console it gives out as many copies as the table has been updated, how to make it give out one copy when clicked. Thanks

from PyQt5.QtCore import QTimer, QTime
from PyQt5.QtWidgets import QApplication, QTableWidgetItem, QTableWidget, QHBoxLayout, QWidget


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.thread = None

        self.layout = QHBoxLayout(self)
        self.layout.setSpacing(0)

        self.table = QTableWidget(self)
        self.layout.addWidget(self.table)

        self.table.setColumnCount(5)
        self.table.setRowCount(5)

        self.timer = QTimer()
        self.timer.timeout.connect(self.row)
        self.timer.start(5000)

    def row(self):
        time = QTime.currentTime()
        text = time.toString('mm:ss')
        print("update table...." + time.toString('mm:ss'))

        for row in range(5):
            item_0 = QTableWidgetItem()
            item_0.setText(text)
            self.table.setItem(row, 0, item_0)

            item_1 = QTableWidgetItem()
            item_1.setText(text)
            self.table.setItem(row, 1, item_1)

            item_2 = QTableWidgetItem()
            item_2.setText(text)
            self.table.setItem(row, 2, item_2)

            item_3 = QTableWidgetItem()
            item_3.setText(text)
            item_3.setCheckState(0)
            self.table.setItem(row, 3, item_3)

        self.table.itemClicked.connect(self.item_clicked)

    def item_clicked(self, item):
        obj = self.table.item(item.row(), 1)
        print(obj.text(), item.checkState())


if __name__ == '__main__':
    qApp = QApplication([])
    app = App()
    app.resize(600, 200)
    app.show()
    qApp.exec()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question