yj_yulin
12th July 2010, 10:17
i have a custom model, and want to achieve the effect in attachment pic.
now i can react on the setdata method in model,like below:
//-------------------------------------------------
bool TorgTreeModel::setData( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole */ )
{
if (!index.isValid())
return true;
TorgTreeItem *item = static_cast<TorgTreeItem*>(index.internalPointer());
if (role == Qt::CheckStateRole && index.column() ==0)
{
item->setCheckState( static_cast<Qt::CheckState>(value.toUInt()));
// emit dataChanged(createIndex(0,0,m_root_item),
// createIndex(m_root_item->childCount()-1,0,m_root_item));
return true;
}
return QAbstractItemModel::setData(index,value,role);
}
i can change all checkstate of the model data for the right value, but i can't tell qtreeview to refresh the new data.
i use beginresetmodel/endresetmodel ,it does refresh,but qtreeview not keep the display layout.
now with my code, when i switch to other program and back, qtreeview display ok, but this is not the solution.
is there any other convenient way to tell the qtreeview update the display?
or there is other way to achieve the same effect?
thanks in advance!
now i can react on the setdata method in model,like below:
//-------------------------------------------------
bool TorgTreeModel::setData( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole */ )
{
if (!index.isValid())
return true;
TorgTreeItem *item = static_cast<TorgTreeItem*>(index.internalPointer());
if (role == Qt::CheckStateRole && index.column() ==0)
{
item->setCheckState( static_cast<Qt::CheckState>(value.toUInt()));
// emit dataChanged(createIndex(0,0,m_root_item),
// createIndex(m_root_item->childCount()-1,0,m_root_item));
return true;
}
return QAbstractItemModel::setData(index,value,role);
}
i can change all checkstate of the model data for the right value, but i can't tell qtreeview to refresh the new data.
i use beginresetmodel/endresetmodel ,it does refresh,but qtreeview not keep the display layout.
now with my code, when i switch to other program and back, qtreeview display ok, but this is not the solution.
is there any other convenient way to tell the qtreeview update the display?
or there is other way to achieve the same effect?
thanks in advance!