Solved Table Navigation with NoItemFlags
-
Hi,
When using NoItemFlags on some cells of a QTableWidget you can't navigate the corresponding lines with Home/End or Ctrl+Home/End. I was wondering if there is a workaround for this or if I should open an issue in the bug tracker.
With best regards, Megamouse
-
Hi,
It's not a bug, you're basically stating that the item can't be select nor do anything else with it therefore you can't navigate through it and that's normal.
Why do you have such items ?
-
@SGaist The table is filled with an undefined number of rows and columns depending on the available screen size, much like a grid.
We fill the leftover empty cells with those items.If I simply don't set those items then I get editable textinputs as cells.
The cells shouldn't be selectable, but the navigation should still work for the rest as expected.
Maybe there's a better approach to make such a tile view?
-
Why not make them just
Qt::ItemIsSelectable
? -
@SGaist said in Table Navigation with NoItemFlags:
ItemIsSelectable
because that does not work either. The behaviour stays the same as with NoItemFlags
-
Can you provide a minimal compilable example that shows that behaviour ?
-
@SGaist I'll try. but I can't promise anything
-
@SGaist if you have the frozencolumn example in Qt Creator you can just add the following to main.cpp in order to make the last item non selectable:
QStandardItem *newItem = new QStandardItem(); newItem->setFlags(Qt::NoItemFlags); model->setItem(model->rowCount() - 1, model->columnCount() - 1, newItem);
keep in mind that you have to have the item in the view to test this properly (maybe reduce the number of rows and cols to 3)
-
@Megamouse
Hi
Try with
newItem->setFlags( Qt::ItemIsSelectable|Qt::ItemIsEnabled ); -
@mrjj said in Table Navigation with NoItemFlags:
Qt::ItemIsSelectable|Qt::ItemIsEnabled
The problem here is that I don't want the selection.
I just want the item to be ignored and the Home/End keys to work in that col/row -
@Megamouse
Ok. well if last item on row is not at least Enabled it wont jump to last on end key.
Home still works. ( to go back to first )
It wont scan to find last that can be End key too, im afraid.
So unless you can live with a tiny selection, im not sure you can make ignore them.
-
@mrjj hmm that's not really an option. If I was content with that I wouldn't have asked :)
I guess the complaining users just have to live with it, unless I work around that issue by overriding the whole navigation (which seems overkill for that) -
@Megamouse
Well the tiny selection rect is far less intrusive than full one. hence i asked.You could try to fix the End key issue with scanning for
a new cell that can have focus. and handle that case your self and
else just call native keyhandling.https://forum.qt.io/topic/97293/qtableview-navigation-with-tab/3
-
@mrjj said in Table Navigation with NoItemFlags:
Home still works. ( to go back to first )
From what I can see in the code I would say Home is going to the first enabled + visible row but End or Ctrl+End goes simply to the last visible row / column without checking for enabled. Is this what you see?
-
@Christian-Ehrlicher
Hi
Actually if last cell is not selectable and or enabled, then the end key do nothing.
Meaning it wont go to last cell (in row) that can have focus/ be selected. -
Ah, I see.
@Megamouse : Can you please create a bug report for it so I've a reference for the bugfix. -
-
@Christian-Ehrlicher
sorry but i've never built Qt myself so i don't really know how to test your commit -
What OS are you on ?
-
@SGaist Windows 10