T
T
Tesla4o2018-09-11 16:12:43
Qt
Tesla4o, 2018-09-11 16:12:43

QTableView and QCheckBox how to select cell value?

There is a code that draws a QTableView and checkboxes are drawn in the first column in a cycle, and rows are loaded in the second column. I need to copy the lines that are selected by the checkbox. I read about diligates, but did not find what I need.
here is the code

QFile file("test.txt");
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {

        QTextStream str(&file);

        quint64 linecount = 0x00;

        QString line;
        QDataStream in;
        
        while (!str.atEnd()) {
            itemCheck = new QStandardItem();
            itemCheck->setCheckable(true);
            iModel->setItem(linecount, 0, itemCheck);
            
            QString line = str.readLine();
            item = new QStandardItem(line);
            iModel->setItem(linecount, 1, item);
            linecount++;
        }

        
        tabl->setModel(iModel);
        tabl->resizeColumnsToContents();
        tabl->resizeRowsToContents();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TriKrista, 2018-09-11
@TriKrista

the delegate is responsible for the visual part of the table.
you need to redefine your table model.
In the general case, you override the setData method in the model, which edits your data structure, and there you then get the data of the required column or row.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question