I have a QTableView where a small mark appears if the mouse hover on active cell. This mark is a widget and emit a signal if hover, changing the selecion mode of the table when I drag over the table. The problem is that if I am over the mark, I can't drag over the table. Things I have tried:
- Set the widget mark like
setWindowFlags(Qt::WindowTransparentForInput);
, but I can't use it because I need hover event. Ignore the events in the widget mark using
event->ignore()
or sending the event to parent using and eventFilter:bool EventFilterMarca::eventFilter(QObject *obj, QEvent *event) { if( event->type() == QEvent::HoverMove) { .... } else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonDblClick) { //QApplication::sendEvent(parent(),event);//one try //event->ignore();//another try return QObject::eventFilter(obj,event);; } }
Subclassing
mousePressEvent
,mouseReleaseEvent
andmouseMoveEvent
in the mark widget and call to parent class. Looks like if it works (pass the event to parent) into the current cell of the table (the parent):
void Marca::mousePressEvent(QMouseEvent *event)
{
//event->setAccepted(false);
if(event->buttons() == Qt::LeftButton)
{
MiTabla* tabla = qobject_cast<MiTabla*>(parent());
if (tabla)
{
tabla->mousePressEvent(event);
//QApplication::sendEvent(parent(),event);
}
}
//event->ignore();
}
Well, the question is how could get that the behaviour of the table was the same if I am over the widget of the cell or directly on the cell.
Also I add a link with my first approach to getting it. It works but the code is awful and not easy to follow:
QItemDelegate
subclass) rather than implementing it as a separate widget. That way it would never interfere when mouse-event handling. – Jeremy Friesner