PDA

View Full Version : QAbstractItemView::entered signal does not fire for QTreeView row when row has widget



Dkrii
7th February 2019, 21:57
When I add a widget to a row in a QTreeView using setIndexWidget(), the QAbstractItemView::entered signal, used to detect when the mouse hovers over a row, does not fire unless the mouse is over the part of the row that the QWidget does not occupy.

See picture below that shows 3 rows.

13019

When the mouse enters the white space it works, but if it enters the green space (the QWidget) it does not. How do I fix this?

This is how the QWidget is put in the row. The QWidget is necessary because I need a clickable button in each row



CustomItem* item= new CustomItem(_uiDoc, *sketch);
parent->appendRow(item);
setIndexWidget(item->index(), item->GetWidget());


Added after 1 15 minutes:

This was the soluton


item->GetWidget()->setAttribute(Qt::WA_TransparentForMouseEvents);

Dkrii
8th February 2019, 16:30
When I add a widget to a row in a QTreeView using setIndexWidget(), the QAbstractItemView::entered signal, used to detect when the mouse hovers over a row, does not fire unless the mouse is over the part of the row that the QWidget does not occupy.

See picture below that shows 3 rows.

13019

When the mouse enters the white space it works, but if it enters the green space (the QWidget) it does not. How do I fix this?

This is how the QWidget is put in the row. The QWidget is necessary because I need a clickable button in each row



CustomItem* item= new CustomItem(_uiDoc, *sketch);
parent->appendRow(item);
setIndexWidget(item->index(), item->GetWidget());


Added after 1 15 minutes:

This was the soluton


item->GetWidget()->setAttribute(Qt::WA_TransparentForMouseEvents);



nevermind, that made the widget then unusable.

ChristianEhrlicher
8th February 2019, 17:03
nevermind, that made the widget then unusable.

And that's the reason why the view does not get events - the widget needs it and doesn't pass it to the view. You have to do it on your own. E.g. by reimplementing QWidget::focusInEvent()