Mouse Hover Problem Sporadically
-
constexpr int TAP_THRESHOLD_TIME = 1000; // Time(ms) diffrence b/w Operation Down and Up event
EventHandler::EventHandler(IScreenObjectVisualProxy* pScreenObjectVisualProxy, QQuickItem* pQQuickItem)
: m_pScreenObjectVisualProxy(pScreenObjectVisualProxy)
, m_pItem(pQQuickItem)
{}bool EventHandler::handleMousePressEvent(QPointF pos, Qt::MouseButton mouseButton)
{
std::shared_ptr<EventInfo> pEventInfo = nullptr;m_bMousePressed = true; m_bMouseMoveReleased = false; m_timerTap.start(); // Used incase of mouseMove event, to trigger Up event when the mouse pressed is moved outside screen item boundary. m_mousePressedPos = pos; if ((mouseButton == Qt::LeftButton) && getEventInfo(EventInfo::RHEventId::Down, pos, pEventInfo, mouseButton)) { TRACE_OUT_F(F::EVENT_HANDLER, _MF("EventInfo is updated with point = %1 , point.y =%2, pEventInfo->m_nElementId = %3") << pos.x() << pos.y() << pEventInfo->m_nElementId); m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo); TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Down")); return true; } else { m_timerTap.elapsed(); } return false;
}
bool EventHandler::handleMouseMoveEvent(QPointF pos, Qt::MouseButton mouseButton)
{
std::shared_ptr<EventInfo> pEventInfo = nullptr;
if (m_bMousePressed && getEventInfo(EventInfo::RHEventId::Pan, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Pan"));
return true;
}// When mouse is still pressed and moved outside screen item boundary, 'Up' event should be triggered. // For widget Leave event is also triggered. if (m_bMousePressed && !pEventInfo) { m_bMousePressed = false; if (getEventInfo(EventInfo::RHEventId::Up, m_mousePressedPos, pEventInfo, mouseButton)) { m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo); TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Up")); m_bMouseMoveReleased = true; } if (getEventInfo(EventInfo::RHEventId::Leave, pos, pEventInfo, mouseButton)) { m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo); TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Leave")); } return true; } return false;
}
bool EventHandler::handleMouseReleaseEvent(QPointF pos, Qt::MouseButton mouseButton)
{
bool bRet = false;
std::shared_ptr<EventInfo> pEventInfo = nullptr;
// After the right/left mouse button has been released then the system triggers "up" event.
if (!m_bMouseMoveReleased)
{
if (getEventInfo(EventInfo::RHEventId::Up, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Up"));
bRet = true;
}
}
if (m_bMousePressed)
{
pEventInfo.reset();
pEventInfo = nullptr;
// IF the left left button is released within 1000 ms , tapped event will be triggered.
// else context tapped will be triggered.
// If the right button release is released irrespective of the time, context tapped event will be triggered.
if ((mouseButton == Qt::LeftButton) && (m_timerTap.elapsed() < TAP_THRESHOLD_TIME) &&
getEventInfo(EventInfo::RHEventId::Tapped, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Mouse Tapped"));
bRet = true;
}
// After the right/left mouse button has been released then the system triggers "ContextTapped".
else if ((mouseButton == Qt::RightButton || mouseButton == Qt::LeftButton) &&
getEventInfo(EventInfo::RHEventId::ContextTapped, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Mouse Context Tapped"));
bRet = true;
}m_bMousePressed = false; } return bRet;
}
bool EventHandler::handleHoverEnterEvent(QPointF pos)
{
std::shared_ptr<EventInfo> pEventInfo = nullptr;
if (getEventInfo(EventInfo::RHEventId::Enter, pos, pEventInfo))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Enter"));
return true;
}
return false;
}bool EventHandler::handleHoverMoveEvent(QPointF pos)
{
bool bRet = false;
std::shared_ptr<EventInfo> pEventInfo = nullptr;
if (getEventInfo(EventInfo::RHEventId::Leave, pos, pEventInfo))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Leave"));
bRet = true;
}
pEventInfo.reset();
pEventInfo = nullptr;
if (getEventInfo(EventInfo::RHEventId::Hover, pos, pEventInfo))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Hover"));
bRet = true;
}
return bRet;
}bool EventHandler::handleHoverLeaveEvent(QPointF pos)
{
std::shared_ptr<EventInfo> pEventInfo = nullptr;
if (getEventInfo(EventInfo::RHEventId::Leave, pos, pEventInfo))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Leave"));
return true;
}
return false;
} -
Hi,
That does not help much more.
You need to provide a clear explanation about what you do, what is happening and what you expect.
Also, reduce your code to the bare minimal so you can provide a minimal compilable example.
Also, post your code between coding tags, that will make it readable unlike the first post in this thread (you can edit it to fix it).
About that code, beside some Qt types here and there, it looks like you either are using some native functionality or some other framework. That's the kind of stuff that you should explain.
-
As already requested, provide a minimal compilable example that shows your issue.
Nobody can help you with the small amount of information you gave.
-
code for mousepress
bool EventHandler::handleMousePressEvent(QPointF pos, Qt::MouseButton mouseButton)
{
std::shared_ptr<EventInfo> pEventInfo = nullptr;m_bMousePressed = true; m_bMouseMoveReleased = false; m_timerTap.start(); // Used incase of mouseMove event, to trigger Up event when the mouse pressed is moved outside screen item boundary. m_mousePressedPos = pos; if (getEventInfo(EventInfo::RHEventId::Down, pos, pEventInfo, mouseButton)) { TRACE_OUT_F(F::EVENT_HANDLER, _MF("EventInfo is updated with point = %1 , point.y =%2, pEventInfo->m_nElementId = %3") << pos.x() << pos.y() << pEventInfo->m_nElementId); m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo); TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Down")); return true; } return false;
}
-
code for mouse release
bool EventHandler::handleMouseReleaseEvent(QPointF pos, Qt::MouseButton mouseButton)
{
bool bRet = false;
std::shared_ptr<EventInfo> pEventInfo = nullptr;
// After the right/left mouse button has been released then the system triggers "up" event.
if (!m_bMouseMoveReleased)
{
if (getEventInfo(EventInfo::RHEventId::Up, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Up"));
m_bMousePressed = false;
m_bMouseMoveReleased = true;
m_timerTap.elapsed();
bRet = true;
}
}
else if (m_bMousePressed)
{
pEventInfo.reset();
pEventInfo = nullptr;
// IF the left left button is released within 1000 ms , tapped event will be triggered.
// else context tapped will be triggered.
// If the right button release is released irrespective of the time, context tapped event will be triggered.
if ((mouseButton == Qt::LeftButton) && (m_timerTap.elapsed() < TAP_THRESHOLD_TIME) &&
getEventInfo(EventInfo::RHEventId::Tapped, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Mouse Tapped"));
bRet = true;
}
// After the right/left mouse button has been released then the system triggers "ContextTapped".
else if ((mouseButton == Qt::RightButton || mouseButton == Qt::LeftButton) &&
getEventInfo(EventInfo::RHEventId::ContextTapped, pos, pEventInfo, mouseButton))
{
m_pScreenObjectVisualProxy->onTriggerMouseEvent(pEventInfo);
TRACE_OUT_F(F::EVENT_HANDLER, _M("Event Triggered: Mouse Context Tapped"));
bRet = true;
}m_bMousePressed = false; } return bRet;
}
-
Can you please provide what was requested and not some snippet of code from your application ?
-
Do you realize that we are running in circles ?
I have already asked you several time to provide a minimal compilable example that shows your issue.
-
void DFQuickItem::hoverEnterEvent(QHoverEvent* pEvent)
{
if ((pEvent == nullptr) || (nullptr == m_pEventHandler))
{
TRACE_OUT_F(F::INFO, _M("pEvent or m_pEventHandler is nullptr "));
return;
}if (!m_pEventHandler->handleHoverEnterEvent(pEvent->pos())) { TRACE_OUT_F(F::INFO, _M("hoverEnter Event is not present for Rete element " "at position x: %1 y: %2") << pEvent->pos().x() << pEvent->pos().y()); }
}
-