Unsolved QCheckBox in QTableView: how to avoid selection menu
-
I put checkboxes in a column of my
QTableView
. For that column I set the following flags:Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEditable;
and in thedata()
function I handled theCheckStateRole
:case Qt::CheckStateRole: switch (index.column()) { case COL_CHECKBOX: return item.enabled ? Qt::Checked : Qt::Unchecked; default: return QVariant(); }
It works, but when I try to (un)flag the checkbox it shows a menu with "True" and "False" items. It's useless for me... I just want to (un)check the
QCheckBox
with one click. Is there a way to do this? -
Looks like you return something for COL_CHECKBOX and Qt::EditRole (or Qt::DisplayRole)
-
@Christian-Ehrlicher Yes, I return something only for
Qt:EditRole
in order to read data from my code. Removing it, it now activate a line edit to write something... still no way to click the checkbox! -
@Mark81 said in QCheckBox in QTableView: how to avoid selection menu:
Qt::ItemIsEditable
I'm not sure but can you try to remove this for COL_CHECKBOX?
-
@Christian-Ehrlicher said in QCheckBox in QTableView: how to avoid selection menu:
I'm not sure but can you try to remove this for COL_CHECKBOX?
Removing the
Qt::ItemIsEditable
from the checkbox column just prevent any further changes to the cell's value.