
Originally Posted by
barnabyr
Hi ...
So, if we could go back to combo boxes for a second, how many clicks on a view item does your program need to open a combo box ? One or more .. ?
Thanks.
You can do it with one click. I implemented my own method which uses a custom delegate and re-implements the editorEvent(). The following code is for a check box, but it wouldn't be much diferent for any other type of widget.
// Trap the mouse button in editorEvent and check/uncheck the checkbox by calling setData()
// which is a subclassed member of the model this delegate is attached to.
bool CheckBoxDelegate
::editorEvent ( QEvent * event,
{
if (event
->type
() == QEvent::MouseButtonRelease) {
bool checkState = index.model()->data(index, Qt::CheckStateRole).toBool();
model->setData(index, !checkState);
}
return true; // Event has been handled here.
}
// Trap the mouse button in editorEvent and check/uncheck the checkbox by calling setData()
// which is a subclassed member of the model this delegate is attached to.
bool CheckBoxDelegate::editorEvent ( QEvent * event,
QAbstractItemModel * model,
const QStyleOptionViewItem & /* option */,
const QModelIndex & index )
{
if (event->type() == QEvent::MouseButtonRelease)
{
bool checkState = index.model()->data(index, Qt::CheckStateRole).toBool();
model->setData(index, !checkState);
}
return true; // Event has been handled here.
}
To copy to clipboard, switch view to plain text mode
Bookmarks