The following doesn't work with a QItemDelegate:
How am I supposed to proceed to catch the enter / leave event of a QItemDelegate ?
Thanks.
Printable View
The following doesn't work with a QItemDelegate:
How am I supposed to proceed to catch the enter / leave event of a QItemDelegate ?
Thanks.
You should check for QStyle::State_MouseOver flag in QStyleOptionViewItem and set the WA_Hover attribute for the viewport to receive paint requests for hover events.
I did that :
Code:
mListView->viewport()->setAttribute(Qt::WA_Hover, true); mListView->viewport()->setMouseTracking(true); { { std::cout << "Tac tac\n"; } }
Not working so far.
Edit :
Solved :
Ok now I have a new problem:
How am I supposed to know when the cursor has left the Item ?
I have a problem with my button, it stays sunken when the cursor goes out of the item while clicking.
I did some research and found this :
void QAbstractItemView::entered ( const QModelIndex & index )
unfortunately there is no "left" signal.
Anyone ?
According to JPN:
I guess that's the direction I'll move forward to. Even if I find it unconvenient.Quote:
For a QTableView you would connect to signals like:
void QAbstractItemView::doubleClicked ( const QModelIndex & index )
void QAbstractItemView::entered ( const QModelIndex & index )
I don't see any particular signal for leaving an item. But of course you can save row/col or a persistent index for the previously colourized cell and uncolourize during the entered signal of another item and possibly leave event of the whole table view.
If you are only after colouring the item, why not do it like this?
Code:
#include <QtGui> public: void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->fillRect(option.rect, Qt::red); } } }; int main(int argc, char **argv){ QTableView tv; tv.viewport()->setAttribute(Qt::WA_Hover); tv.setModel(&model); tv.setItemDelegate(new Delegate(&tv)); tv.show(); return app.exec(); }