I am now suspecting that it is in fact my model that is not allowing for the color change but am not sure. Could this be possible? Here is my simple implementation, with some irrelevant stuff removed:
InternalScanDatabase
::InternalScanDatabase(QObject *parent
){
// Set up the root of the database.
QList<QVariant> rootData;
rootData<<"Scan Directory";//<<"File Path";
rootItem = new ScanDatabaseItem(rootData);
// Make the root the start of the database list.
Database<<rootItem;
}
InternalScanDatabase::~InternalScanDatabase()
{
delete rootItem;
Temp.close(); // Debugging only.
}
int InternalScanDatabase
::columnCount(const QModelIndex &parent
) const {
if (parent.isValid())
return static_cast<ScanDatabaseItem*>(parent.internalPointer())->columnCount();
else
return rootItem->columnCount();
}
{
if (!index.isValid())
if (role != Qt::DisplayRole)
ScanDatabaseItem *item = static_cast<ScanDatabaseItem*>(index.internalPointer());
return item->data(index.column());
}
Qt
::ItemFlags InternalScanDatabase
::flags(const QModelIndex &index
) const{
if (!index.isValid())
return Qt::ItemIsEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant InternalScanDatabase
::headerData(int section, Qt
::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
}
const
{
ScanDatabaseItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<ScanDatabaseItem*>(parent.internalPointer());
ScanDatabaseItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
}
{
if (!index.isValid())
ScanDatabaseItem *childItem = static_cast<ScanDatabaseItem*>(index.internalPointer());
ScanDatabaseItem *parentItem = childItem->parent();
if (parentItem == rootItem)
return createIndex(parentItem->row(), 0, parentItem);
}
int InternalScanDatabase
::rowCount(const QModelIndex &parent
) const {
ScanDatabaseItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<ScanDatabaseItem*>(parent.internalPointer());
return parentItem->childCount();
}
InternalScanDatabase::InternalScanDatabase(QObject *parent)
: QAbstractItemModel(parent)
{
// Set up the root of the database.
QList<QVariant> rootData;
rootData<<"Scan Directory";//<<"File Path";
rootItem = new ScanDatabaseItem(rootData);
// Make the root the start of the database list.
Database<<rootItem;
}
InternalScanDatabase::~InternalScanDatabase()
{
delete rootItem;
Temp.close(); // Debugging only.
}
int InternalScanDatabase::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return static_cast<ScanDatabaseItem*>(parent.internalPointer())->columnCount();
else
return rootItem->columnCount();
}
QVariant InternalScanDatabase::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
ScanDatabaseItem *item = static_cast<ScanDatabaseItem*>(index.internalPointer());
return item->data(index.column());
}
Qt::ItemFlags InternalScanDatabase::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant InternalScanDatabase::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section);
return QVariant();
}
QModelIndex InternalScanDatabase::index(int row, int column, const QModelIndex &parent)
const
{
ScanDatabaseItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<ScanDatabaseItem*>(parent.internalPointer());
ScanDatabaseItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
QModelIndex InternalScanDatabase::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
ScanDatabaseItem *childItem = static_cast<ScanDatabaseItem*>(index.internalPointer());
ScanDatabaseItem *parentItem = childItem->parent();
if (parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
int InternalScanDatabase::rowCount(const QModelIndex &parent) const
{
ScanDatabaseItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<ScanDatabaseItem*>(parent.internalPointer());
return parentItem->childCount();
}
To copy to clipboard, switch view to plain text mode
Bookmarks