PDA

View Full Version : QTableWidget row selection



BingoMaster
16th October 2009, 23:01
I been dealing with this QTableWidget for several days, and got most of what I want except one simple thing.

When I select on a row, it shows a box around the item column that I clicked on. I want to treat the row as a comlete selection as the table is a read only table. I know I am doing something increditable hard that should be simple.

I haven't needed to post in over 2 weeks as I am learning, but I swear I have read every help line there is.

Thanks.

squidge
16th October 2009, 23:41
Doesn't QTableWidget inherit from QAbstractItemView, which has setSelectionBehavior?

ie. obj->setSelectionBehavior(QAbstractItemView::SelectRows );

Don't just read the docs for the widget your using, you need to read the docs for the inherited classes too :)

EDIT: Why is "SelectRows" all one word in the editor, but "SelectRow s" in the viewer? :confused:

Lykurg
16th October 2009, 23:47
there are some posts about how to remove the focus rectangle. For an graphics item it would be
QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*> (option);
o->state &= ~QStyle::State_HasFocus;
QGraphicsRectItem::paint(painter, o, widget);
For a table widget it is similar and you have to alter the QItemDelegate::paint() method and set your custom delegate to the table. Try to achieve that. If you have trouble (and it is kind of hard if you just started with Qt, but try it) ask again.

Lykurg
16th October 2009, 23:55
Don't just read the docs for the widget your using, you need to read the docs for the inherited classes too :)
But he is talking about the dotted border around the item he has clicked not about how to select a row.


EDIT: Why is "SelectRows" all one word in the editor, but "SelectRow s" in the viewer? :confused:
If you would use the CODE tags, it wouldn't occur:


obj->setSelectionBehavior(QAbstractItemView::SelectRows );

BingoMaster
17th October 2009, 22:22
Lykurg:

Thank you and I will try this. You are correct that I am trying to hide the dotted lines.

Row selection isn't an issue, the fact that you have to override a paint when row selection is already set seem like a bug. But most likely there are hundreds of good reasons for this.

Thank again for you help, and I will post if I was sucessful or not.

Lykurg
17th October 2009, 22:39
the fact that you have to override a paint when row selection is already set seem like a bug.

No it's not. Selection and focus are two different things. And to indicate which item inside a multi-item-selection is "selected"/focused you need that dotted line. So in normal case it's perfect. Your case is special, because you don't need the information which item is focused. So small reimplement and all is fine. I've done that a lot of times myself...