QTableView Column Click and Select
-
Hi i have a table view
I want Table view columns always have multiple selections so i apply QAbstractItemView::MultiSelection attribute.However, I had a problem. I want to make one of 10 columns not selectable even when clicked. The reason is that you want to do something different.
Is there a way?
-
Thanks your answer !
Not Selectable option was given in the flag of the view model, but it was not selected even if the column was selected.
However, when a row is selected, the columns are not displayed as the rest of the selected columns. Can I solve this?
-
@Qt-Jo-Ha
Not sure I understand your question.Once items are not selectable, then when you select a whole row those columns which are not selectable will not show with selected background color. That is what you wanted, you stated:
I want to make one of 10 columns not selectable even when clicked.
So, yes, they do not display as the rest of the columns in the row.
-
@Qt-Jo-Ha
Yes, because if you want "non-selectable" it can't be selected, so it doesn't show in blue. That's precisely what you asked for, and what you get.So now the question is: what do you mean by wanting "non-selectable", since that's what you now have but do not want? You need to explain what you are looking for.
For example, do you mean: "When a row is selected, I do want the column to be shown as selected, just like the other columns. But I just do not want that column to be clickable to select the row"? Is that what you want, something about you can't click to select the row on that column, but the column is selectable like all other columns in terms of it showing it is selected? Which seems like an odd requirement.... If it's that, you have instead to look at the clicks on the table, and not allow a row to be selected when the item clicked is in that column.
-
@Qt-Jo-Ha
I'm sorry, but I still don't find that you are explaining what it is you do want/need, as you're not distinguishable between selectable versus clickable.I can only repeat what I said above, which is my best guess:
-
If you want the column to show in blue just like the other columns, then just like them you must allow it to have the
Qt::ItemIsSelectable
flag. -
At that point, it is automatically clickable too. If you want to forbid that, you must deal with that at the mouse-click level, ignoring that if it's in your "non-clickable" column. So far as I know, that's what you'll need to do.
I still don't know why you want to forbid certain columns to be "click-to-select". If you want columns for "select" & "delete" those should (IMHO) have buttons (or links) to click on to accomplish, and again has nothing to do with whether the column cell, which does no harm to allow as normal selectable & clickable.
-