I promote my QLineEdit
to a custom widget and trying to reimplement mouse event handlers. I need to handle all mouse events except mouseDoubleClickEvent()
by parent of my QLineEdit
-based widget (parent is a custom scrollable area). All works well except wheelEvent()
. QLineEdit
is still handle mouse wheel and parent is still not.
Here is my promoted QLineEdit
:
HeightLineEdit::HeightLineEdit(QWidget* parent) :
QLineEdit(parent)
{
this->setFocusPolicy(Qt::NoFocus);
}
void HeightLineEdit::mousePressEvent(QMouseEvent* event)
{
event->ignore();
}
void HeightLineEdit::mouseMoveEvent(QMouseEvent* event)
{
event->ignore();
}
void HeightLineEdit::mouseReleaseEvent(QMouseEvent* event)
{
event->ignore();
}
void HeightLineEdit::mouseDoubleClickEvent(QMouseEvent* event)
{
this->setFocus();
this->selectAll();
}
void HeightLineEdit::wheelEvent(QWheelEvent* event)
{
event->ignore();
}
From the
QWheelEvent
documentation: "Wheel events are sent to the widget under the mouse cursor, but if that widget does not handle the event they are sent to the focus widget."If you want the parent to handle them for the child widget, you can either install an event filter on the child widget, or you could directly call a method on the parent widget from the child's
wheelEvent
method.