View Full Version : checkable items in QTableView
cgorac
11th March 2008, 13:11
Got QTableView with a column containing checkable items. In order to toggle corresponding check box, one need to click exactly over the check box; clicking over other parts of the same cell is not affecting the check box. In most of other cases, check box could be toggled clicking on accompanying text label, so - is there any way to force same behavior here?
Thanks.
wysota
11th March 2008, 13:40
You can connect the clicked() signal to a custom slot where you will toggle the check state yourself.
THRESHE
11th March 2008, 13:42
Maybe you should do something like
connect(tableView, SIGNAL(clicked(const QModelIndex & index )), this, SLOT(Handler));
and check this checkbox manually ?
Wysota ;)
cgorac
11th March 2008, 20:57
That method almost works, but has a big issue: when clicked on check box, the event gets processed twice, so actually we have inverse of default behavior: user could toggle check box clicking on given item anywhere except on the check box itself...
wysota
11th March 2008, 21:26
I think that you can remove the ItemIsUserCheckable flag from the model to disable one of the events. The checkbox should still be visible if you set data for Qt::CheckStateRole.
cgorac
11th March 2008, 22:35
Yep - this is all rather ugly (moreover - now it is impossible to toggle check box using Space button), but it works now... Many thanks for both suggestions!
wysota
11th March 2008, 22:45
I think space causes the activated() signal to be emitted, so you can connect it to the same handler and it should work just fine.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.