Reputation: 12381
Stupid question, but I can't find the way out of this crap about an hour. I have a QTableView
widget, trying to add rows with QStandardItemModel
. In ctor, before
tableView->setModel( MyStandardItemModel );
I run this function:
void MyDialog::addItem( const SomeSection& section )
{
SignalBlocker< QStandardItemModel > blocker( model_ );
QStandardItem* visibilityItem = new QStandardItem;
visibilityItem->setCheckable( true );
visibilityItem->setCheckState( !section.hidden ? Qt::Checked : Qt::Unchecked );
visibilityItem->setData( QVariant::fromValue( section ), Qt::UserRole + 1 );
QStandardItem* descriptionItem = new QStandardItem( section.name );
QStandardItem* signatureItem = new QStandardItem;
if( section.sign )
{
signatureItem->setToolTip( tr( "Требует подписи" ) );
signatureItem->setIcon( QIcon( ":/signatures/images/signatures/check-sgn.png" ) );
}
model_->appendRow( StandardItemList() << visibilityItem << descriptionItem << signatureItem );
}
PS: StandardItemList
is just a typedef QList< QStandardItem* > StandardItemList;
So first of all I made some addItem()'s
and then setModel()
and all rows are visible in a table. BUT when I'm trying to append another row later (at this time from the button clicked), with
addItem( MyNewSection );
I don't see the changes in QTableView
widget (no new row and no new MyNewSection data in it)! I think that I have to "update" model content somehow, but I can't find correct methods from model documentation...
Any help?
Thanks!
Upvotes: 0
Views: 5300
Reputation: 25155
The code creating and adding the items to the model looks correct.
If SignalBlocker
does what I suspect it to do, I suppose that it causes your troubles.
When you're adding items, the model emits signals that the view connects to, updating as you add the item. If you call blockSignals(true)
on the model, you prevent any signals from being emitted, and the view isn't notified of the changes.
Upvotes: 2