PDA

View Full Version : QtreeWidgetItem: setFlags emits QTreeWidget::itemChanged



trallallero
15th November 2011, 12:47
From the doc http://doc.qt.nokia.com/stable/qtreewidgetitem.html#setFlags:


void QTreeWidgetItem::setFlags ( Qt::ItemFlags flags )

Sets the flags for the item to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item.

and from http://doc.qt.nokia.com/stable/qtreewidget.html#itemChanged:


void QTreeWidget::itemChanged ( QTreeWidgetItem * item, int column ) [signal]

This signal is emitted when the contents of the column in the specified item changes.

But when I call item->setFlags(...) with which I don't change the contents of the column, a itemChanged signal is thrown.
My problem is that I have a plugin connected to that signal and it should react only when the content has been changed, not the flags.

Is there an elegant way to solve this problem ? (I have a solution but it looks more like a hack).

thanks

MarekR22
15th November 2011, 13:12
This depend on interpretation of contents of item.
IMO flags are part of item contents, since it has impact on how item can be visualized (as you quote documentation: "This is often used to disable an item.")
Check the flag values: http://doc.trolltech.com/latest/qt.html#ItemFlag-enum
Qt::ItemIsEnabled, Qt::ItemIsTristate, Qt::ItemIsUserCheckable - those flags are definitely have impact on how item is drawn (content).

Maybe you should try to connect to different signal, for example QAbstractItemModel::dataChanged (http://doc.qt.nokia.com/latest/qabstractitemmodel.html#dataChanged) .

trallallero
16th November 2011, 08:04
Yes, probably it's right, itemChanged is thrown because the flags of the item are changed.
But the docs specifies "the content of the item", this is why I was a bit surprised when I've seen that the signal is thrown also when I change the flags.
Thanks for the suggestion but how should I use that signal ? I've never used models, that's my problem.
I guess I have to connect to the model of the QTableWidget...

Added after 5 minutes:

I've tried now in this way:


connect (m_TreeWidget->model(), SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)),
this , SLOT (ItemDataChanged(const QModelIndex&, const QModelIndex&)) );

but the signal is emitted also when the flags are set.
Thanks anyway.

SKolaMunn
27th January 2012, 20:51
Did you ever find a solution? I have a similar problem. My slot that I connected to the itemChanged signal is being called way too often. I want to only know when the checkstate is changed, is that possible? Any suggestions?

trallallero
30th January 2012, 08:58
I've solved in this (hacky) way:


void PluginOptions::On_itemDoubleClicked(QTreeWidgetIte m *item, int column)
{
m_SessionActive = true;

<set the flags>

m_SessionActive = false;
}

void PluginOptions::On_itemChanged(QTreeWidgetItem* item, int column)
{
if (m_SessionActive)
return;
<...>
}