R
R
runcode2018-11-08 22:06:03
Python
runcode, 2018-11-08 22:06:03

How to implement settings for the table?

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem, QMainWindow, QApplication, QTableWidget


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.tablewidget = QTableWidget(4, 1)
        self.setCentralWidget(self.tablewidget)

        for row in range(4):
            item = QTableWidgetItem("index_" + str(row))
            item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            item.setCheckState(Qt.Unchecked)
            self.tablewidget.setItem(row, 0, item)

        self.tablewidget.cellChanged.connect(self.onCellChanged)

    def onCellChanged(self, row, column):
        item = self.tablewidget.item(row, column)
        print(item.text())

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

There is a table with a checkbox , how to save their state to the setting.ini file when closing and then load it? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Klimanov, 2018-11-08
@ahmpro

Separate display and data. Store checkboxes in a separate object, update the state of these flags when the UI changes.
And reading/writing ini files via https://docs.python.org/3/library/configparser.html can be done

B
bbkmzzzz, 2018-11-08
@bbkmzzzz

Alternatively, you can use QtCore.QSettings
Initialize to work with ini:
QSettings("path_to_ini_file", QSettings,IniFormat)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question