[Interest] custom delegate for view not working

Etienne Sandré-Chardonnal etienne.sandre at m4x.org
Wed Jul 12 12:57:35 CEST 2017


Dear All,

I have a plain QTreeView, and I want to display some of the icons as greyed
depending on some state of the model items

So I have subclassed QStyledItemDelegate :

class SceneObjectsDelegate : public QStyledItemDelegate

{

public:

	explicit SceneObjectsDelegate(QObject *parent = nullptr) :
QStyledItemDelegate(parent) {}


protected:

	void initStyleOption(QStyleOptionViewItem *option, const QModelIndex
&index) const override

	{

		QStyledItemDelegate::initStyleOption(option, index);

		int flags = index.data(RefTreeModel::FlagsRole).toInt();

		if (flags & RefTreeModel::Shadowed)

		{

			option->state &= ~QStyle::State_Enabled;

		}

	}

};



Then I set this delegate when creating my view:

treeView = new QTreeView(this);
treeView->setModel(sceneHandler->refModel());
treeView->setItemDelegate(new SceneObjectsDelegate(this));


This is not working, and I checked initStyleOption is never called.
I'm 100% sure that a similar code has worked by the past. What can I do
wrong?

Thanks!

Etienne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170712/bac0f898/attachment.html>


More information about the Interest mailing list