PDA

View Full Version : Navigate through QTableWidget



darshan.hardas
17th December 2008, 06:01
Hi All,

I have encountered a small problem in QTableWiget.

I want to navigate through table widget created programatically on Windows.
Some of the items in table are non-editable and flags are set as


QTableWigetItem* item = new QTableWidgetItem(str);
qTableWiget->setItem(row, column, item);
item->setFlags(item->flags() & (~Qt::ItemIsEditable));

I have intialize the table item with default properties as gets set in designer.


qTableWiget->setTabKeyNavigation(true);
qTableWiget->setAutoScroll(true);
qTableWiget->setHorizontalScrollMode(QAbstractItemView::ScrollP erItem);
qTableWiget->setVerticalScrollMode(QAbstractItemView::ScrollPer Item);
qTableWiget->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
qTableWiget->setEditTriggers(QAbstractItemView::AnyKeyPressed |
QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);

When I clicked on any of the item, it gets selected.
But when I use arrow keys or tab key, no other item gets selected.

Please let me know your suggestions on it.

caduel
17th December 2008, 15:03
Note the existence of two different concepts: selection and "current item". These are independent.
The selection is what you know (blue background), the current is a rather hard to see dotted rectangle.

Clicking selects the item (and also makes it current). Note that often the whole row is selected, but only one cell of it is current.

With the arrow keys you usually move the current item, not the selection.


If you insist on being able to do an extended selection, there is no way around that behaviour: how would you select rows 1 and 3 (with keyboard only) if hitting arrow keys moved the selection=?
If single selection should suffice, try QAbstractItemView::SingleSelection as selection mode. Maybe current and selection are held in sync then.

HTH