From 435bbd4be73768f617e4a4083a345d1d8d62daa3 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 5 Aug 2009 15:06:49 +0200 Subject: ItemViews: make it possible for chekcable items to get partiallyChecked Previously it was only switching between checked and unchecked. Task-number: 259008 Reviewed-by: ogoffart --- src/gui/itemviews/qitemdelegate.cpp | 8 +++++++- src/gui/itemviews/qstyleditemdelegate.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/itemviews/qitemdelegate.cpp b/src/gui/itemviews/qitemdelegate.cpp index 962ce54..bd6dc62 100644 --- a/src/gui/itemviews/qitemdelegate.cpp +++ b/src/gui/itemviews/qitemdelegate.cpp @@ -1296,8 +1296,14 @@ bool QItemDelegate::editorEvent(QEvent *event, return false; } - Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked + Qt::CheckState state; + if ( flags & Qt::ItemIsTristate ) { + state = static_cast( (value.toInt() + 1) % 3 ); + } else { + state = (static_cast(value.toInt()) == Qt::Checked ? Qt::Unchecked : Qt::Checked); + } + return model->setData(index, state, Qt::CheckStateRole); } diff --git a/src/gui/itemviews/qstyleditemdelegate.cpp b/src/gui/itemviews/qstyleditemdelegate.cpp index 8faf0be..34667ee 100644 --- a/src/gui/itemviews/qstyleditemdelegate.cpp +++ b/src/gui/itemviews/qstyleditemdelegate.cpp @@ -746,8 +746,13 @@ bool QStyledItemDelegate::editorEvent(QEvent *event, return false; } - Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked + Qt::CheckState state; + if ( flags & Qt::ItemIsTristate ) { + state = static_cast( (value.toInt() + 1) % 3 ); + } else { + state = (static_cast(value.toInt()) == Qt::Checked ? Qt::Unchecked : Qt::Checked); + } return model->setData(index, state, Qt::CheckStateRole); } -- cgit v0.12