PDA

View Full Version : Best practice for dynamic update of QTabelView



regenwo62
20th March 2020, 14:14
I have an application(QT 5.11.2, linux) with 200 cells. The text in 20 … 40 cells change every second. Now I us the dataChanged signal for update the QTabelView. I use one signal per cell.
If I send a dataChanged with more than one cell, always the whole table was updated.

Is QTableView the right widget or is QTableWidget better?

Is there a better way to update the cells?

Code samples
class Xdatamodel : public QAbstractTableModel
void Xdatamodel::setModelData(int rowindex, int dataitem, QString value)
{
dataMatrix[rowindex].operator [](dataitem) = value;
emit(dataChanged(index(rowindex,dataitem), index(rowindex,dataitem),
}

QVariant Xdatamodel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
return dataMatrix[index.row()].at(index.column());
}

ChristianEhrlicher
20th March 2020, 15:35
Since you're already using a custom model you have to use QTableView. One signal per cell is fine.