Unsolved QTreeWidgetItem Disable | Enable
-
Hi. @VRonin
Yes I use it.
But when I disable the item and I move anothar item I can not go back To get involved.QTreeWidgetItem * last = ui->treeWidget->currentItem(); **!BLOCKED**
-
If you ant to go back you can set the
Qt::ItemIsSelectable
flag -
QTreeWidgetItem * last = ui->treeWidget->currentItem(); if (last == top) { return; } last->setFlags(Qt::NoItemFlags); last->setFlags(Qt::ItemIsSelectable);
it not work :X
-
Could you put down a quick bullet list with:
- what you are doing in the GUI
- what you expect to happen
- what happens instead
-
-
@VRonin
I can not select disabled item, problem it is. -
What's the difference between an enabled and disabled item? just the colour of the text? Does the behaviour change between the two?
-
@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
-
@VRonin
I'm not good enough to understand your words.
I will think of something else.-
last->SetChecked( Qt::Checked or Qt :: Unchecked ); // bla bla bla
-
Or replace an icon.
Just to understand the user.
-