mugi
8th July 2011, 23:41
Hi,
I need to add checkboxes to the first three columns in a QTreeView which gets its data
from a QAbstractItemModel .
Could some one tell me how to complete my model, so that the user can freely check and uncheck theses checkboxes.
QModelIndex OutputsListModel::index ( int row, int column, const QModelIndex & parent) const
{
return createIndex(row, column);
}
QModelIndex OutputsListModel::parent ( const QModelIndex & index ) const
{
return QModelIndex();
}
int OutputsListModel::rowCount ( const QModelIndex & parent) const
{
return(r);
}
int OutputsListModel::columnCount ( const QModelIndex & parent) const
{
return(c);
}
bool OutputsListModel::hasChildren ( const QModelIndex & parent ) const
{.....
}
QVariant OutputsListModel::data ( const QModelIndex & index, int role) const
{ int i = index.column();
if(role == Qt::DisplayRole)
{.....
}
}
Qt::ItemFlags OutputsListModel::flags(const QModelIndex& index) const
{
if (i == 0 || i== 1 || i == 2)
return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
bool OutputsListModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
return true;
}
I need to add checkboxes to the first three columns in a QTreeView which gets its data
from a QAbstractItemModel .
Could some one tell me how to complete my model, so that the user can freely check and uncheck theses checkboxes.
QModelIndex OutputsListModel::index ( int row, int column, const QModelIndex & parent) const
{
return createIndex(row, column);
}
QModelIndex OutputsListModel::parent ( const QModelIndex & index ) const
{
return QModelIndex();
}
int OutputsListModel::rowCount ( const QModelIndex & parent) const
{
return(r);
}
int OutputsListModel::columnCount ( const QModelIndex & parent) const
{
return(c);
}
bool OutputsListModel::hasChildren ( const QModelIndex & parent ) const
{.....
}
QVariant OutputsListModel::data ( const QModelIndex & index, int role) const
{ int i = index.column();
if(role == Qt::DisplayRole)
{.....
}
}
Qt::ItemFlags OutputsListModel::flags(const QModelIndex& index) const
{
if (i == 0 || i== 1 || i == 2)
return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled;
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
bool OutputsListModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
return true;
}