QTreeWidgetItem Disable | Enable
Unsolved
General and Desktop
-
How To Disable | Enable QTreeWidgetCurrentItem?
void wdgMyTree::PauseSLOT() { QTreeWidgetItem * last = ui->treeWidget->currentItem(); if (last == top) { return; } last->setDisabled( !last->isDisabled() ); if (globalall->db.open()) { QSqlQuery qry; qry.prepare("update Tree Set Pause = :value where UID = : uid"); qry.bindValue(":uid", mpuid[last]); qry.bindValue(":value", last->isDisabled() ? 1 : 0); qry.exec(); globalall->db.close(); } }
When the item is turned off and the last item changes, I will not allow you to get involved.
I can not stand on the disabled item. -
@VRonin said in QTreeWidgetItem Disable | Enable:
What's the difference between an enabled and disabled item? just the colour of the text? Does the behaviour change between the two?
No.
If I'm turned on or off, I'll have to decide on the following steps. -
Then you are misusing
setDisabled
.- set the a boolean in the
Qt::UserRole
(true when is disabled)if(last->data(Qt::UserRole).toBool()) last->setData(Qt::UserRole,QVariant()); else last->setData(Qt::UserRole,true);
- reimplement
QStyledItemDelegate::paint
to use it.- starting from the original source: https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html#_ZNK19QStyledItemDelegate5paintEP8QPainterRK20QStyleOptionViewItemRK11QModelIndex
- replace
QStyledItemDelegatePrivate::widget(option);
withoption.widget;
- add
if(index.data(Qt::UserRole).toBool()) option.state &= ~QStyle::State_Enabled;
in the line belowinitStyleOption
- apply the delegate to the view
- in the constructor call
ui->treeWidget->setItemDelegate(new MyDelegate(this));
- in the constructor call
- set the a boolean in the