QTreeWidget: forbid forcing PartiallyChecked on parent tristate items.
ItemIsTristate means QTreeWidget determines the check state of parent items based on the check state of child items. Checking/unchecking the parent propagates to children; but setting the parent to PartiallyChecked shouldn't do that, especially since it can lead to children without ItemIsTristate having PartiallyChecked check state. Change-Id: Ibc8b7c77d9ec4c1578c07f3c62581edb770f8439 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
This commit is contained in:
parent
4910f416c2
commit
dd23d9f161
@ -1720,7 +1720,7 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value)
|
||||
}
|
||||
} break;
|
||||
case Qt::CheckStateRole:
|
||||
if (itemFlags & Qt::ItemIsTristate) {
|
||||
if ((itemFlags & Qt::ItemIsTristate) && value != Qt::PartiallyChecked) {
|
||||
for (int i = 0; i < children.count(); ++i) {
|
||||
QTreeWidgetItem *child = children.at(i);
|
||||
if (child->data(column, role).isValid()) {// has a CheckState
|
||||
|
@ -1048,6 +1048,12 @@ void tst_QTreeWidget::checkState()
|
||||
QCOMPARE(item->checkState(0), Qt::Unchecked);
|
||||
QCOMPARE(firstChild->checkState(0), Qt::Unchecked);
|
||||
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked);
|
||||
|
||||
// Can't force the state to PartiallyChecked; state comes from children
|
||||
item->setCheckState(0, Qt::PartiallyChecked);
|
||||
QCOMPARE(item->checkState(0), Qt::Unchecked);
|
||||
QCOMPARE(firstChild->checkState(0), Qt::Unchecked);
|
||||
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked);
|
||||
}
|
||||
|
||||
void tst_QTreeWidget::findItems_data()
|
||||
|
Loading…
x
Reference in New Issue
Block a user