Ok, you really have to tell me more, because right now I can't move forward. Let's go the first thing you suggested - implement it in the model. I tried this:
{
private:
bool highlighted;
public:
HighlightModelItem(void);
explicit HighlightModelItem
(const QString & text
);
HighlightModelItem
(const QIcon & icon,
const QString & text
);
explicit HighlightModelItem(int rows, int columns = 1);
virtual ~HighlightModelItem(void);
void setHighlighted(bool value);
};
class HighlightModelItem : public QStandardItem
{
private:
bool highlighted;
public:
HighlightModelItem(void);
explicit HighlightModelItem(const QString & text);
HighlightModelItem(const QIcon & icon, const QString & text);
explicit HighlightModelItem(int rows, int columns = 1);
virtual ~HighlightModelItem(void);
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
void setHighlighted(bool value);
};
To copy to clipboard, switch view to plain text mode
(BTW, I had no idea how subclassing should look like, I can't find EVEN ONE example on the internet... so I just reimplemented ctors/dtor from QStandardItem. :P)
{
if (role == Qt::BackgroundColorRole && highlighted)
{
}
return data(index, role);
}
void HighlightModelItem::setHighlighted(bool value)
{
highlighted = value;
emitDataChanged();
}
QVariant HighlightModelItem::data(const QModelIndex & index, int role) const
{
if (role == Qt::BackgroundColorRole && highlighted)
{
return QColor(255, 0, 0);
}
return data(index, role);
}
void HighlightModelItem::setHighlighted(bool value)
{
highlighted = value;
emitDataChanged();
}
To copy to clipboard, switch view to plain text mode
And I'm just using this instead of QStandardItem in QStandardItemModel object:
blocksModel->setHorizontalHeaderItem(0, new HighlightModelItem("Blocks"));
inputCategory = new HighlightModelItem("Input blocks");
processCategory = new HighlightModelItem("Processing blocks");
outputCategory = new HighlightModelItem("Output blocks");
blocksModel->setItem(0, inputCategory);
blocksModel->setItem(1, processCategory);
blocksModel->setItem(2, outputCategory);
treeView->setModel(blocksModel);
QStandardItemModel * blocksModel = new QStandardItemModel();
blocksModel->setHorizontalHeaderItem(0, new HighlightModelItem("Blocks"));
inputCategory = new HighlightModelItem("Input blocks");
processCategory = new HighlightModelItem("Processing blocks");
outputCategory = new HighlightModelItem("Output blocks");
blocksModel->setItem(0, inputCategory);
blocksModel->setItem(1, processCategory);
blocksModel->setItem(2, outputCategory);
treeView->setModel(blocksModel);
To copy to clipboard, switch view to plain text mode
But, as you can guess, this doesn't work. "HighlightModelItem::data()" never gets called (despite me calling HighlightModelItem::setHighlighted()" in my code), why is that?
Bookmarks