+ 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 Respostas
+ 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 'SelectItems'.
This works ok for me in case of rows are very limit. I have 25 rows and would like to modify one column value for all rows. This forces me to select all rows one by one which is tedious process.
So, I thought to set selection behavior as SelectColumns. This helps me select entire column in a single click. But with this option, I lost the provision to modify a single cell.
How to achieve both i.e. single cell modification and option to modify an entire column without a need to select an individual all rows?
Again, many thanks for your help on this topic.
+ 1
Bob_Li I have other functionality on header select. Still can I do this behaviour?
Muhammad Nouman Ali can you please share a sample code link for me to start with? I understand there might not be an exact solution matching my requirement but just pointers will also be helpful
+ 1
Ketan Lalcheta Sure I can help you 😊 code :
Link to Code Playground:
https://sololearn.com/compiler-playground/c2Nd4c521Vyo/?ref=app
If you like and Rate My Code 🤗
+ 1
Thanks Muhammad Nouman Ali but on qt side. Sololearn does not support qt. Right?
+ 1
Ketan Lalcheta Yes, Sololearn does not support Qt. Use Qt Creator or a local development environment for Qt.
+ 1
Okay Bob_Li . If I had a option on right click, then it should be a checkbox. Right? If checkbox is checked , then set selection behaviour as column or else let section behaviour is item.
What if I need one column as entire selected but for other column as cell.
+ 1
That's correct Bob_Li . Right click is defined on column and should not affect the other column.
But behaviour is on table. Table object has provision to set it as item selectable or column selectable
+ 1
Bob_Li Yes, a global column or row selection can add complexity and confuse users. 😊