Thanks for the hint. Lets not over kill it. I already have the sub-classed Model from QAbstractItemModel. And i have over-ridden the data(...) as follows:
{
if (!index.isValid())
H3DTreeItem *item = static_cast<H3DTreeItem*>(index.internalPointer());
if(role == Qt::DecorationRole)
{
return QIcon(":/H3D/images/Node.png");
}
/*
display role is used to access string that
can be displayed as text in the view
*/
else if(role == Qt::DisplayRole)
{
return item->data(index.column());
}
else if(role == Qt::UserRole)
{
return QPixmap(":/H3D/images/Node.png");
}
else if(role == Qt::ToolTipRole)
{
//return item->data(index.column());
if(m_nodeFactory)
{
return m_nodeFactory->getNodeData(item->data(index.column()).toString())->nodeData();
}
else
return item->data(index.column());
}
// else if(role == Qt::BackgroundRole)
// {
// return item->data(index.column());
// }
// else if(role == Qt::BackgroundColorRole)
// {
// return item->data(index.column());
// }
// else if(role == Qt::ForegroundRole)
// {
// return item->data(index.column());
// }
else
}
QVariant H3DTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
H3DTreeItem *item = static_cast<H3DTreeItem*>(index.internalPointer());
if(role == Qt::DecorationRole)
{
return QIcon(":/H3D/images/Node.png");
}
/*
display role is used to access string that
can be displayed as text in the view
*/
else if(role == Qt::DisplayRole)
{
return item->data(index.column());
}
else if(role == Qt::UserRole)
{
return QPixmap(":/H3D/images/Node.png");
}
else if(role == Qt::ToolTipRole)
{
//return item->data(index.column());
if(m_nodeFactory)
{
return m_nodeFactory->getNodeData(item->data(index.column()).toString())->nodeData();
}
else
return item->data(index.column());
}
// else if(role == Qt::BackgroundRole)
// {
// return item->data(index.column());
// }
// else if(role == Qt::BackgroundColorRole)
// {
// return item->data(index.column());
// }
// else if(role == Qt::ForegroundRole)
// {
// return item->data(index.column());
// }
else
return QVariant();
}
To copy to clipboard, switch view to plain text mode
What other changes i have to do over this model subclasses so that the entered line edit string pattern will match the item in the tree-views and high-light it or expand and high-light it.
Regards
Sajjad
Bookmarks