+ 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 Réponses
+ 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
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
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
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
Thanks Muhammad Nouman Ali but on qt side. Sololearn does not support qt. Right?
+ 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
Ketan Lalcheta
number 1 requirement sounds like standard behavior.
number 2 sounds like a multi-edit operation, like in ide modifying multiple lines at the same time. maybe
https://stackoverflow.com/questions/14586715/how-can-i-achieve-to-update-multiple-rows-in-a-qtableview
+ 1
I got your point, but how to differentiate between two options ?
Checkbox on context menu like what Muhammad Nouman Ali was suggesting or something else.
I also in line of your thought that it is confusion to user , but do we have any other option?
+ 1
No Muhammad Nouman Ali All I want is in QT and not on normal code.
+ 1
I hope I am not sounding rude Muhammad Nouman Ali . I don't mean it if it feels so.
But this is also not the same. I should not be asked to provide new value.
User should be editing cell and that cell modification is done once, it should either remain to that cell or should populate to entire column
+ 1
My concern is how to differentiate whether to populate all cells In a column or to keep it with only one cell. What is best option to differentiate
+ 1
Ketan Lalcheta
unfortunately I cannot test out some things you asserted:
"we don't have option to select single cell or entire column at the same time..."
as I have stopped coding Qt some years ago and don't have it installed in my current setup. I rarely use it and it was taking up too much space.
Anyway, that statement is ambiguous to me. We are not doing it at the same time. The select single cell is the default behavior. The select entire column is the special right click behavior. They occur at different times.
0
Click to select rows & columns, right click to find grading of marks various degree course marklist.
Various types of data product prcing list check in tabular format.