[Qt-interest] Making a QTableView's cells look like 3D Buttons: Can't get mouse events

Neil Hooey nhooey at gmail.com
Thu Jun 25 23:24:27 CEST 2009


I'm trying to modify the display behaviour of a QTableView. All I want
to do is make the cells look like 3D "buttons", in that when you click
them they have a visual "pressed" state.

Right now, I'm handling this with an ItemDelegate, that draws an image
for the default and pressed states. It's working alright, except that
when you click and drag one of the cells, and drag outside of the
table without hovering over any other cells, the ItemDelegate still
thinks that particular cell has focus and leaves the button in the
pressed state. If you let go outside of the table, the button just
stays pressed until you do something else inside the QTableView.

Below I'm going to describe what I've tried to do to fix this bug. If
you know of a much better way to make a QTableView have 3D buttons,
I'm open to ideas. Here is what I tried:

In the ItemDelegate, I check if a particular cell is being clicked by
testing if this is true:
QStyleOptionViewItem::state & QStyle::State_HasFocus

I've already tried checking this to see if the mouse is truly on the
current cell:
QStyle::State_MouseOver

And I made sure I called this:
QTableView::setMouseTracking(true);

Which doesn't work, since apparently a QTableView won't pass on any
sort of mouse events.

I even tried this:
QTableView::installEventFilter(&MyMouseMonitor);

And had it intercept all events to the QTableView. It doesn't get any
mouse move events, since I could see prints occuring after doing some
things with the table, but not mouse overing or click dragging.

Is there a way to get a QTableView to report when a mouse is being
click dragged over it? Or is there any way you can tell if the mouse
cursor is on a particular cell at any given moment?

Thanks,

- Neil



More information about the Qt-interest-old mailing list