PDA

View Full Version : Clicking Whitespace in a table



shooogun
10th March 2008, 00:12
Hi All,

I've been trying to work out how to deselect all cells in a table, by selecting white space in the table.

My table has a set height and width, and is initially empty, so theres a lot of white space. When I add a row and select it, I can't deselect it by clicking the whitespace below. Thats what I'm trying to solve.

I'm using a QTableWidget as my table. Is there anyway to do that?

jpn
10th March 2008, 12:36
Reimplement mousePressEvent() and clear selection if itemAt() returns 0 for event->pos(). Don't forget to call the base class implementation to keep it aware of mouse press events.

shooogun
11th March 2008, 00:34
Awesome, thanks for the help jpn!

I did what you said, and its nearly working . I added


def mousePressEvent(self, event):
if not self.table.itemAt(event.pos()):
self.table.clearSelection()

It works when I click anywhere on the interface, but not on the whitespace of the table, or other widgets. Has that got something to do with calling the base class? I don't understand the last comment you made. Do I have to make the table aware of mouse events?

jpn
11th March 2008, 06:23
Looks like you reimplemented mousePressEvent() of the widget which contains the table. Instead, you should have reimplemented mousePressEvent() of the table itself.

shooogun
27th March 2008, 00:20
Hey again,

I had to move on to other fixes, so I put this on hold for a while. I understand what you mean jpn, but how do I re-implement the mouse press event of the table. Has that got something to do with the signature?

jpn
27th March 2008, 06:29
Subclass QTableWidget and reimplement it for the table. Just like you subclassed QWidget and reimplemented it for the window so far.