+ 3
QT table selection as column and cell
I have a qt table and i want to allow user to either select one cell or entire column. In other words, I need both the provisions i.e. to allow one cell modification or entire column modification. I am using API QAbstractItemView::setSelectionBehavior with QAbstractItemView::SelectItems or QAbstractItemView::SelectColumns. How to allow both these behaviours?
34 ответов
+ 3
have you read this?
https://forum.qt.io/topic/28464/select-a-single-column-in-qtableview
+ 3
can you set it up so that the select entire column is only triggered when the column header is clicked? This is how it's often done in spreadsheets.
Also, if the entire column is selected, alt-click should deselect the clicked cell.
+ 2
The issue is that `setSelectionBehavior` can only handle one mode at a time. You need custom logic to differentiate between cell and column selection.
+ 2
Ketan Lalcheta
maybe add the select entire column to a custom right click menu?
+ 2
Ketan Lalcheta
I'm not sure, but wouldn't the right click be context sensitive? I imagine that the right click would depend on which cell or header you right clicked on, not on the entire table, so other columns should not be involved ..
+ 2
Ketan Lalcheta Add a checkbox to the right-click menu for selecting an entire column. If the checkbox is checked, select the whole column; if unchecked, select individual cells.
+ 2
I think a global column or row selection for the entire table would be counter-productive and only adds to overall complexity.
Wouldn't it lead to a confusing user experience?
Its easier to place the cursor over the cell or header, then right click, select column or row, then do other operations, rather than checking and unchecking a global option whenever you want cell selection or row/column selection, and mistakenly selecting entire column or row when you just want to select a cell, because you forgot that the option is on.
But this is just a personal preference. Maybe some people prefer one over the other.
+ 2
Now This Code the provided code is for a Qt application and cannot be run in the Sololearn compiler, as Sololearn only supports standard C++ without GUI libraries :
https://sololearn.com/compiler-playground/ccsOv9Q2Myv3/?ref=app
+ 2
Ketan Lalcheta No Problem Wait now I am going to update code I'll help you 🙂👍
+ 2
Thanks for your patience and support of you and Bob_Li
+ 1
I had taken an overview of the same. It suggests how to stop selecting more than one column at a time.
My concern is about option to select one cell or entire column both.
Once I set option QAbstractItemView::SelectColumns through QAbstractItemView::setSelectionBehavior, any selection of cell results into entire column selection. I need to have an option to either continue editing a cell or choose to edit entire column.
+ 1
what you are describing sounds like alt-clicking, or perhaps ctrl-clicking? or maybe shift-select? Not sure which, but holding down a modifier key while left clicking things...
https://forum.qt.io/topic/46348/qt-creator-column-edit
+ 1
Perfect...!
I got fair idea that I can select multiple cells in a column by pressing alt key along with left mouse button. This is allowed when selection behavior is set as 'SelectIte