QTableView not refreshing
Hi,
I'm using my own model derived from QAbstractTableModel. My class looks something like :
Code:
{
Q_OBJECT
public:
~DATreeModel();
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
) const;
void setCanData( const QString& strData );
void SetHeaders( QStringList& strHeaders );
private:
QList<QString> m_Data;
};
This model is just read only so no need to override setData. Now the following snippet of code is used to set the data :
Code:
QVariant DATreeModel
::data( const QModelIndex
& index,
int role
) const {
if (!index.isValid())
if (index.row() > (m_Data.size() / 4) )
{
}
if(index.column() > 3 )
{
}
if( role == Qt::DisplayRole )
{
// just return data at given column
int nPos = index.column() + ( 4 * index.row() );
if( nPos < m_Data.size() )
data = m_Data.at( nPos );
}
return data;
}
And the following is used to insert new data :
Code:
void DATreeModel::setCanData( const QString& strData )
{
m_Data.append(strData);
emit dataChanged(nindex, nindex );
}
Alas, the table view is not 'refreshed' unless I click on the cells within it, I thought this would be automatic?
Any help would be much appreciated.
Steve
Re: QTableView not refreshing
Quote:
Originally Posted by
steg90
Alas, the table view is not 'refreshed' unless I click on the cells within it, I thought this would be automatic?
Make the model aware of the insertion with:
Re: QTableView not refreshing
Thanks,
Do I need to implement these functions in my model?
Regards,
Steve
Re: QTableView not refreshing
Hi again,
I've now done this, thanks JPN ;)
Re: QTableView not refreshing
An alternative is to emit layoutChanged() after inserting new data.