PDA

View Full Version : A problem about QAbstractItemView::EditTriggers



hoffen
10th October 2011, 08:44
Hi everyone~
I used a ComboBox with checkboxes as its items in my program, this checkbox is inherited from QStyledItemDelegate.
now I wanna check these checkboxes, but I used setEditTriggers(CurrentChanged) to initiate item editing. And of course
this will not work when I put only one checkbox in the combobox. So is there any way to initiate item editing when I hover
my mouse on the checkbox? Or how can I make it work even there is only one checkbox in the combobox?
Thanks a lot!

QAbstractItemView::SelectedClicked will work but click twice on a checkbox seems weird ~~

wysota
10th October 2011, 08:47
I don't understand what problem you have however I can answer your question. If you want to initiate editing upon hover then simply intercept proper mouse event (you'll need mouse tracking enabled) and call edit(). But before doing that think if it is necessary. If all you want is checkboxes in items then the best way is to use Qt::ItemIsUserCheckable in your model. Then the default delegate will render a checkbox for your item and provide means of checking and unchecking it.

hoffen
10th October 2011, 09:02
Thank you for replying! Sorry I'm not expressing myself clearly .. here is the combobox I used : http://da-crystal.net/2008/06/checkbox-in-qcombobox/ (http://da-crystal.net/2008/06/checkbox-in-qcombobox/) my problem is , if there is a single checkbox , I can not check it.

wysota
10th October 2011, 09:13
Yeah, that's a poor implementation of a checkable combobox. I suggest you use the approach I proposed instead. I cannot help you with this faulty code.

hoffen
11th October 2011, 03:56
Thanks, I solved it using a QStandardItemModel with its flags(const QModelIndex& index) returns QStandardItemModel::flags(index) | Qt::ItemIsUserCheckable;