QTableview change number
-
I am using QtableView.
I want to change the number in the red box. What should I do?And I have one more question.
For example, you have 100 values in a list variable.
Is there a way to add the entire list instead of adding one by one with a loop statement? -
I am using QtableView.
I want to change the number in the red box. What should I do?And I have one more question.
For example, you have 100 values in a list variable.
Is there a way to add the entire list instead of adding one by one with a loop statement?@IknowQT said in QTableview change number:
I want to change the number in the red box. What should I do?
This comes from
QTableView::horizontalHeader()
(I think it;s that one, I always get confused about which header is horizontal vs vertical!). So useQTableView:setHorizontalHeader()
. And/or, look at what your model'sQAbstractItemModel::headerData()
is returning and change that or useQAbstractItemModel::setHeaderData()
.Is there a way to add the entire list instead of adding one by one with a loop statement?
Depends on what your model is, e.g.
QStringListModel
hasQStringListModel::setStringList()
. Yours looks like multiple columns though, you can create blank rows viainsertRows()
but to fill them with data you need to callsetData()
in a loop. -
@IknowQT said in QTableview change number:
I want to change the number in the red box. What should I do?
This comes from
QTableView::horizontalHeader()
(I think it;s that one, I always get confused about which header is horizontal vs vertical!). So useQTableView:setHorizontalHeader()
. And/or, look at what your model'sQAbstractItemModel::headerData()
is returning and change that or useQAbstractItemModel::setHeaderData()
.Is there a way to add the entire list instead of adding one by one with a loop statement?
Depends on what your model is, e.g.
QStringListModel
hasQStringListModel::setStringList()
. Yours looks like multiple columns though, you can create blank rows viainsertRows()
but to fill them with data you need to callsetData()
in a loop. -
Hmm...
So is this even possible?
I want to add data in units of table columns.
Can I append data column by column using QAbstractTableModel?
Since data is accumulated over time, it is not possible to accumulate data in the model from the beginning.@IknowQT
You did not seem to so anything about those horizontal header numbers even though that was your previous question.I think you are now asking whether you can add new columns to a
QAbstractTableModel
as you go along? Sure, there is virtual bool QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()). I have not used it, but I would imagine your attachedQTableView
has a slot onQAbstractItemModel::columnsInserted()
and will redraw as required. You still have to callsetData()
for the content of the new columns. Yes, you have to do that in a loop, not just in one blob for a whole column, but I don't know why you seem to see that as an issue/problem. -
@IknowQT
You did not seem to so anything about those horizontal header numbers even though that was your previous question.I think you are now asking whether you can add new columns to a
QAbstractTableModel
as you go along? Sure, there is virtual bool QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()). I have not used it, but I would imagine your attachedQTableView
has a slot onQAbstractItemModel::columnsInserted()
and will redraw as required. You still have to callsetData()
for the content of the new columns. Yes, you have to do that in a loop, not just in one blob for a whole column, but I don't know why you seem to see that as an issue/problem.I did not understand very well.
I'm a bit poor at English.
I found out that it can be implemented by calling the beginInsertColumns function as a way to add columns.m_pModel = new usrTableModel; m_pModel->SetheaderName("Wave Length"); m_pModel->InsertColumns(0, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); QModelIndex a = m_pModel->index(0, 1, QModelIndex()); qDebug() << m_pModel->data(m_pModel->index(0,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(1,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(2,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(3,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(4,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(5,0), Qt::DisplayRole); QList<qreal> asd; asd.append(333); asd.append(334); asd.append(335); asd.append(336); asd.append(337); asd.append(338); m_pModel->SetRowData(asd); m_pModel->InsertColumns(1, 1, QModelIndex(), asd); a = m_pModel->index(0, 2, QModelIndex()); /*qDebug() << m_pModel->data(m_pModel->index(0, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(1, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(2, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(3, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(4, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(5, 1), Qt::DisplayRole);*/ this->ui.tableWidget->setModel(m_pModel); this->ui.tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 행 단위로 선택
When the first insertColums is called, the data of m_pSpectrumInfo->GetWaves() Qlist is inserted well.
When the second InsertColumns is called, the data is overwritten on the existing row, not the row is added.
What should I do in this case?In the case of QStandardItemModel, it seems that data can be inserted by accessing each row with setitem.
Would the same be possible with QAbstractTableModel?
The final thing I want to do is use the QVXYModelMapper to link it to the chart. -
I did not understand very well.
I'm a bit poor at English.
I found out that it can be implemented by calling the beginInsertColumns function as a way to add columns.m_pModel = new usrTableModel; m_pModel->SetheaderName("Wave Length"); m_pModel->InsertColumns(0, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); QModelIndex a = m_pModel->index(0, 1, QModelIndex()); qDebug() << m_pModel->data(m_pModel->index(0,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(1,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(2,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(3,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(4,0), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(5,0), Qt::DisplayRole); QList<qreal> asd; asd.append(333); asd.append(334); asd.append(335); asd.append(336); asd.append(337); asd.append(338); m_pModel->SetRowData(asd); m_pModel->InsertColumns(1, 1, QModelIndex(), asd); a = m_pModel->index(0, 2, QModelIndex()); /*qDebug() << m_pModel->data(m_pModel->index(0, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(1, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(2, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(3, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(4, 1), Qt::DisplayRole); qDebug() << m_pModel->data(m_pModel->index(5, 1), Qt::DisplayRole);*/ this->ui.tableWidget->setModel(m_pModel); this->ui.tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); // 행 단위로 선택
When the first insertColums is called, the data of m_pSpectrumInfo->GetWaves() Qlist is inserted well.
When the second InsertColumns is called, the data is overwritten on the existing row, not the row is added.
What should I do in this case?In the case of QStandardItemModel, it seems that data can be inserted by accessing each row with setitem.
Would the same be possible with QAbstractTableModel?
The final thing I want to do is use the QVXYModelMapper to link it to the chart.@IknowQT
I'm afraid I don't understand what you are asking.When the second InsertColumns is called, the data is overwritten on the existing row, not the row is added.
Why should inserting columns have anything to do with adding rows??
In the case of QStandardItemModel, it seems that data can be inserted by accessing each row with setitem.
Would the same be possible with QAbstractTableModel?
QStandardItemModel
does not do anything you cannot do yourself.setItem()
--- and the whole "items" thing --- is just a layer thatQStandardItemModel
adds for your convenience. Ultimately it does everything viasetData()
and/orinsertRows()
, so you can do the same thing in yourQAbstractTableModel
-derived class.If you have "dedicated" methods in your
QAbstractTableModel
-derived class which offer things like "insert a whole column of data in one go", you do not have to callsetData()
and/orinsertRows()
. You can alter your underlying data model directly. just it must emit the required signals, likedataChanged()
/begin
/endInsertRows()
for whatever it does on the underlying model, so that e.g. attachedQTableView
s know what has happened in the model. -
@IknowQT
I'm afraid I don't understand what you are asking.When the second InsertColumns is called, the data is overwritten on the existing row, not the row is added.
Why should inserting columns have anything to do with adding rows??
In the case of QStandardItemModel, it seems that data can be inserted by accessing each row with setitem.
Would the same be possible with QAbstractTableModel?
QStandardItemModel
does not do anything you cannot do yourself.setItem()
--- and the whole "items" thing --- is just a layer thatQStandardItemModel
adds for your convenience. Ultimately it does everything viasetData()
and/orinsertRows()
, so you can do the same thing in yourQAbstractTableModel
-derived class.If you have "dedicated" methods in your
QAbstractTableModel
-derived class which offer things like "insert a whole column of data in one go", you do not have to callsetData()
and/orinsertRows()
. You can alter your underlying data model directly. just it must emit the required signals, likedataChanged()
/begin
/endInsertRows()
for whatever it does on the underlying model, so that e.g. attachedQTableView
s know what has happened in the model.@JonB said in QTableview change number:
QStandardItemModel의 경우 setitem으로 각 행에 접근하여 데이터를 삽입할 수 있을 것 같습니다.
m_pModel->InsertColumns(0, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); m_pModel->InsertColumns(1, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); void usrTableModel::InsertColumns(int nPos, int nRow, const QModelIndex& index, const QList<qreal>& data) { beginInsertColumns(QModelIndex(), nPos, nRow+nRow-1); { SetRowData(data); } endInsertColumns(); }
I called InsertColumns twice and the result is that only one appears and overwrites with the last insert value.
Is it possible to manage models separately for each row?
The reason I asked this question is because it seems that speed problems may occur when the number of data increases. -
@JonB said in QTableview change number:
QStandardItemModel의 경우 setitem으로 각 행에 접근하여 데이터를 삽입할 수 있을 것 같습니다.
m_pModel->InsertColumns(0, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); m_pModel->InsertColumns(1, 1, QModelIndex(), m_pSpectrumInfo->GetWaves()); void usrTableModel::InsertColumns(int nPos, int nRow, const QModelIndex& index, const QList<qreal>& data) { beginInsertColumns(QModelIndex(), nPos, nRow+nRow-1); { SetRowData(data); } endInsertColumns(); }
I called InsertColumns twice and the result is that only one appears and overwrites with the last insert value.
Is it possible to manage models separately for each row?
The reason I asked this question is because it seems that speed problems may occur when the number of data increases.@IknowQT said in QTableview change number:
overwrites with the last insert value.
Because you call a custom function SetRowData() without any information where this data has to be set. Also we don't know what this function does at all.
-
@IknowQT said in QTableview change number:
overwrites with the last insert value.
Because you call a custom function SetRowData() without any information where this data has to be set. Also we don't know what this function does at all.
I will post the code.
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); lstTemp.append(pairTemp); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); //m_pModel->AppendData(lstTemp); //this->ui.tableWidget->setModel(m_pModel); } ================ AbstrectTableModel ================== int usrTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData[0].second.count(); } int usrTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData.count(); } QVariant usrTableModel::headerData(int section, Qt::Orientation orientation, int role) const { //section: 행 Index if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (m_lstInputData.count() != 0 ) return m_lstInputData[section].first; } else return QString("%1").arg(section + 1); } void usrTableModel::SetheaderName(QString strTitle) { m_strTitle = strTitle; } QVariant usrTableModel::data(const QModelIndex& index, int role) const { if (role == Qt::DisplayRole) { if (m_lstInputData.count() != 0) return m_lstInputData[index.column()].second.at(index.row()); //return m_lstInputData[index.column()].second->at(index.row()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::EditRole) { return m_lstInputData[index.column()].second.at(index.row()); } return QVariant(); } bool usrTableModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { m_lstInputData[index.column()].second.replace(index.row(), value.toDouble()); emit dataChanged(index, index); return true; } return false; } Qt::ItemFlags usrTableModel::flags(const QModelIndex& index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void usrTableModel::SetRowData(const QList< QPair<QString, QList<qreal>> >& data) { m_lstInputData = data; } void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { m_lstInputData.append(data); }
If you setModel after appending the same data, two data will appear in TableView normally.
I want to append data at different points in time. So I appended, but the appended data does not appear in TableView.When data is updated in Qlist, I want to automatically update TableView as well.
-
I will post the code.
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); lstTemp.append(pairTemp); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); //m_pModel->AppendData(lstTemp); //this->ui.tableWidget->setModel(m_pModel); } ================ AbstrectTableModel ================== int usrTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData[0].second.count(); } int usrTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData.count(); } QVariant usrTableModel::headerData(int section, Qt::Orientation orientation, int role) const { //section: 행 Index if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (m_lstInputData.count() != 0 ) return m_lstInputData[section].first; } else return QString("%1").arg(section + 1); } void usrTableModel::SetheaderName(QString strTitle) { m_strTitle = strTitle; } QVariant usrTableModel::data(const QModelIndex& index, int role) const { if (role == Qt::DisplayRole) { if (m_lstInputData.count() != 0) return m_lstInputData[index.column()].second.at(index.row()); //return m_lstInputData[index.column()].second->at(index.row()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::EditRole) { return m_lstInputData[index.column()].second.at(index.row()); } return QVariant(); } bool usrTableModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { m_lstInputData[index.column()].second.replace(index.row(), value.toDouble()); emit dataChanged(index, index); return true; } return false; } Qt::ItemFlags usrTableModel::flags(const QModelIndex& index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void usrTableModel::SetRowData(const QList< QPair<QString, QList<qreal>> >& data) { m_lstInputData = data; } void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { m_lstInputData.append(data); }
If you setModel after appending the same data, two data will appear in TableView normally.
I want to append data at different points in time. So I appended, but the appended data does not appear in TableView.When data is updated in Qlist, I want to automatically update TableView as well.
@IknowQT said in QTableview change number:
I will post the code.
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); lstTemp.append(pairTemp); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); //m_pModel->AppendData(lstTemp); //this->ui.tableWidget->setModel(m_pModel); } ================ AbstrectTableModel ================== int usrTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData[0].second.count(); } int usrTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData.count(); } QVariant usrTableModel::headerData(int section, Qt::Orientation orientation, int role) const { //section: 행 Index if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (m_lstInputData.count() != 0 ) return m_lstInputData[section].first; } else return QString("%1").arg(section + 1); } void usrTableModel::SetheaderName(QString strTitle) { m_strTitle = strTitle; } QVariant usrTableModel::data(const QModelIndex& index, int role) const { if (role == Qt::DisplayRole) { if (m_lstInputData.count() != 0) return m_lstInputData[index.column()].second.at(index.row()); //return m_lstInputData[index.column()].second->at(index.row()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::EditRole) { return m_lstInputData[index.column()].second.at(index.row()); } return QVariant(); } bool usrTableModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { m_lstInputData[index.column()].second.replace(index.row(), value.toDouble()); emit dataChanged(index, index); return true; } return false; } Qt::ItemFlags usrTableModel::flags(const QModelIndex& index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void usrTableModel::SetRowData(const QList< QPair<QString, QList<qreal>> >& data) { m_lstInputData = data; } void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { m_lstInputData.append(data); }
If you setModel after appending the same data, two data will appear in TableView normally.
I want to append data at different points in time. So I appended, but the appended data does not appear in TableView.When data is updated in Qlist, I want to automatically update TableView as well.
void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { QModelIndex a = QModelIndex(); beginInsertColumns(QModelIndex(), m_lstInputData.count(), 1); m_lstInputData.append(data); endInsertColumns(); }
I tried to do this, but the value of QModelIndex comes out as -1.
-
@IknowQT said in QTableview change number:
I will post the code.
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); lstTemp.append(pairTemp); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); //m_pModel->AppendData(lstTemp); //this->ui.tableWidget->setModel(m_pModel); } ================ AbstrectTableModel ================== int usrTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData[0].second.count(); } int usrTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData.count(); } QVariant usrTableModel::headerData(int section, Qt::Orientation orientation, int role) const { //section: 행 Index if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (m_lstInputData.count() != 0 ) return m_lstInputData[section].first; } else return QString("%1").arg(section + 1); } void usrTableModel::SetheaderName(QString strTitle) { m_strTitle = strTitle; } QVariant usrTableModel::data(const QModelIndex& index, int role) const { if (role == Qt::DisplayRole) { if (m_lstInputData.count() != 0) return m_lstInputData[index.column()].second.at(index.row()); //return m_lstInputData[index.column()].second->at(index.row()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::EditRole) { return m_lstInputData[index.column()].second.at(index.row()); } return QVariant(); } bool usrTableModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { m_lstInputData[index.column()].second.replace(index.row(), value.toDouble()); emit dataChanged(index, index); return true; } return false; } Qt::ItemFlags usrTableModel::flags(const QModelIndex& index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void usrTableModel::SetRowData(const QList< QPair<QString, QList<qreal>> >& data) { m_lstInputData = data; } void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { m_lstInputData.append(data); }
If you setModel after appending the same data, two data will appear in TableView normally.
I want to append data at different points in time. So I appended, but the appended data does not appear in TableView.When data is updated in Qlist, I want to automatically update TableView as well.
void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { QModelIndex a = QModelIndex(); beginInsertColumns(QModelIndex(), m_lstInputData.count(), 1); m_lstInputData.append(data); endInsertColumns(); }
I tried to do this, but the value of QModelIndex comes out as -1.
@IknowQT said in QTableview change number:
@IknowQT said in QTableview change number:
I will post the code.
void wSpectrum::InitTableWidget() { QList<QPair<QString, QList<qreal>>> lstTemp; QPair<QString, QList<qreal>> pairTemp; pairTemp.first = "WaveLength"; pairTemp.second = m_pSpectrumInfo->GetWaves(); lstTemp.append(pairTemp); lstTemp.append(pairTemp); m_pModel = new usrTableModel(lstTemp); this->ui.tableWidget->setModel(m_pModel); //m_pModel->AppendData(lstTemp); //this->ui.tableWidget->setModel(m_pModel); } ================ AbstrectTableModel ================== int usrTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData[0].second.count(); } int usrTableModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent) return m_lstInputData.count(); } QVariant usrTableModel::headerData(int section, Qt::Orientation orientation, int role) const { //section: 행 Index if (role != Qt::DisplayRole) return QVariant(); if (orientation == Qt::Horizontal) { if (m_lstInputData.count() != 0 ) return m_lstInputData[section].first; } else return QString("%1").arg(section + 1); } void usrTableModel::SetheaderName(QString strTitle) { m_strTitle = strTitle; } QVariant usrTableModel::data(const QModelIndex& index, int role) const { if (role == Qt::DisplayRole) { if (m_lstInputData.count() != 0) return m_lstInputData[index.column()].second.at(index.row()); //return m_lstInputData[index.column()].second->at(index.row()); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::EditRole) { return m_lstInputData[index.column()].second.at(index.row()); } return QVariant(); } bool usrTableModel::setData(const QModelIndex& index, const QVariant& value, int role) { if (index.isValid() && role == Qt::EditRole) { m_lstInputData[index.column()].second.replace(index.row(), value.toDouble()); emit dataChanged(index, index); return true; } return false; } Qt::ItemFlags usrTableModel::flags(const QModelIndex& index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } void usrTableModel::SetRowData(const QList< QPair<QString, QList<qreal>> >& data) { m_lstInputData = data; } void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { m_lstInputData.append(data); }
If you setModel after appending the same data, two data will appear in TableView normally.
I want to append data at different points in time. So I appended, but the appended data does not appear in TableView.When data is updated in Qlist, I want to automatically update TableView as well.
void usrTableModel::AppendData(const QList<QPair<QString, QList<qreal>>>& data) { QModelIndex a = QModelIndex(); beginInsertColumns(QModelIndex(), m_lstInputData.count(), 1); m_lstInputData.append(data); endInsertColumns(); }
I tried to do this, but the value of QModelIndex comes out as -1.
void usrTableModel::AppendData(const QPair<QString, QList<qreal>>& data) { m_lstInputData.append(data); int nNewCol = this->columnCount(); beginInsertColumns(QModelIndex(), nNewCol, nNewCol); endInsertColumns(); QModelIndex a = QModelIndex(); QModelIndex index = createIndex(m_lstInputData[0].second.count(), m_lstInputData.count()); emit dataChanged(index, index); }
I implemented it like this and it prints normally.