diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-08-05 13:06:49 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-08-05 13:08:15 (GMT) |
commit | 435bbd4be73768f617e4a4083a345d1d8d62daa3 (patch) | |
tree | a42509305619a9f8154fa8bbe95d96ca47a930f9 | |
parent | e95166da34d1f5f383e9595d4042ce3e835efdc2 (diff) | |
download | Qt-435bbd4be73768f617e4a4083a345d1d8d62daa3.zip Qt-435bbd4be73768f617e4a4083a345d1d8d62daa3.tar.gz Qt-435bbd4be73768f617e4a4083a345d1d8d62daa3.tar.bz2 |
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
-rw-r--r-- | src/gui/itemviews/qitemdelegate.cpp | 8 | ||||
-rw-r--r-- | 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<Qt::CheckState>(value.toInt()) == Qt::Checked + Qt::CheckState state; + if ( flags & Qt::ItemIsTristate ) { + state = static_cast<Qt::CheckState>( (value.toInt() + 1) % 3 ); + } else { + state = (static_cast<Qt::CheckState>(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<Qt::CheckState>(value.toInt()) == Qt::Checked + Qt::CheckState state; + if ( flags & Qt::ItemIsTristate ) { + state = static_cast<Qt::CheckState>( (value.toInt() + 1) % 3 ); + } else { + state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked ? Qt::Unchecked : Qt::Checked); + } return model->setData(index, state, Qt::CheckStateRole); } |