QWidget::enterEvent is not being triggered when mouse button is pressed
-
I am implementing custom QSplitterHandle which I want to get working some different way. I have to handle situation when user starts dragging over SplitterHandle widget. But it does not work when the mouse button is pressed.
The question is how can I handle that.Constructor:
@
BetterSplitterHandle::BetterSplitterHandle(Qt::Orientation orientation, QSplitter * parent) :
QSplitterHandle(orientation, parent)
{
setMouseTracking(true);
}
@current implementation for event:
@
void BetterSplitterHandle::enterEvent(QEvent *event)
{
qDebug("b"); //works only when mouse buttons are released
}
@I have try dragEnterEvent, but it doesn't work neither.
PS: Sory for my english :)
-
Off hand, this sounds like a mouse grab issue. When a button is clicked, Qt grabs all mouse input and sends it to the widget that the cursor was over when the button was clicked.
http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse
Perhaps an event filter will do the job without too much work.
-
[quote author="jeremy_k" date="1411939385"]Off hand, this sounds like a mouse grab issue. When a button is clicked, Qt grabs all mouse input and sends it to the widget that the cursor was over when the button was clicked.[/quote]
OK, perhabs you are right, but the main problem is where (inside which event) should I call the grabMouse method?
-
OK, I found solution (or maybe it is only workaround) with jeremy's tip - I have reimplemented mouseMoveEvent of parent's widget (in my case it is QSplitter's child class):
@
void SidebarsLayout::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() | Qt::LeftButton) {
if (event->pos().x() < width()/2) {
firstHandle()->grabMouse();
} else {
lastHandle()->grabMouse();
}
}
}
@As you can see this is not perfect solution, as only one SplitterHandle can grab mouse events at time, and I have to calculate which one. In my case it is satisfactory, but if someone have better solution, I would like to see it.