QTableView, no selection rectangle
Hi,
Is it possible to hide the selection rectangle for the table view items when the item is highlighted and selected ?
I mean what I want is to select the cell and paint its background but I don't want to see the dotted selection rectangle around the cell.
Sami
Re: QTableView, no selection rectangle
try this
or you can implement your own delegate and do not draw selection.
Re: QTableView, no selection rectangle
Actually what I want is to select a row when I click on a cell, and I'm using setSelectionMode(QAbstractItemView::SingleSelectio n) and setSelectionBehavior(QAbstractItemView::SelectRows ).
What I don't want is the dotted rectangle displayed when I click on a cell. It can be easily seen when selection mode is set to `NoSelection`. It does not selects the cell, but the active cell is shown with this rectangle.
Re: QTableView, no selection rectangle
now it's clear. so, you need to implement your own delegate and don't draw dotten focus rect.
Re: QTableView, no selection rectangle
Code:
view->setFocusPolicy(Qt::NoFocus);
Re: QTableView, no selection rectangle
Quote:
Originally Posted by
jpn
Code:
view->setFocusPolicy(Qt::NoFocus);
what about keyboard navigation in this case? it will not work.
Re: QTableView, no selection rectangle
What's the point of having focus if he wants to hide it? :)
Re: QTableView, no selection rectangle
that's true. :) but I think he wants to have keyboard navigation I think. :)
Re: QTableView, no selection rectangle
Quote:
Originally Posted by
jpn
What's the point of having focus if he wants to hide it? :)
that will do the trick but there is a minor bug ( I guess this is not a feature :) ), when focus is deactivated, when a cell is double clicked for editing, after the editing, the focus rectangle becomes active again.
setting the item flags to un-editable mode fixes that problem.
is there a way to set the table as read-only so that none of the items are editable?
Re: QTableView, no selection rectangle
Quote:
Originally Posted by
spirit
that's true. :) but I think he wants to have keyboard navigation I think. :)
Yeah actually I may need keyboard navigation. But I guess I can implement keyboard inputs to change the selected rows, without using the focus.
Re: QTableView, no selection rectangle
do you think this is bet solution to implement navigation of treeView which is already works fine insted of creating custom delegate and write several lines of code? I don't thinks so.
Re: QTableView, no selection rectangle
Quote:
Originally Posted by
spirit
do you think this is bet solution to implement navigation of treeView which is already works fine insted of creating custom delegate and write several lines of code? I don't thinks so.
can you describe which part I have to reimplement so that I can lose the focus rectangle?
the main reason why I want to do such things is that, I want to implement an outlook-like message list, and I think the best way is to use QTableWidget. do I proceed in the right direction or do you have any other suggestion ?
Re: QTableView, no selection rectangle
example
Code:
{
Q_OBJECT
public:
};
...
table->setItemDelegate(new MyDelegate());
for (int row = 0; row < 10; ++row) {
for (int col = 0; col < 10; ++col) {
table->setItem(row, col, item);
}
}
...
Re: QTableView, no selection rectangle
Quote:
Originally Posted by
spirit
example
Code:
{
Q_OBJECT
public:
};
...
table->setItemDelegate(new MyDelegate());
for (int row = 0; row < 10; ++row) {
for (int col = 0; col < 10; ++col) {
table->setItem(row, col, item);
}
}
...
Thanks a lot Spirit, for not giving up on me :)
I finally got what I need.
Sami