fix:single click to select word does not work properly

This commit is contained in:
yifang 2022-01-06 23:43:46 +08:00
parent 93f75d1cf5
commit 4d648aca09

View file

@ -73,12 +73,10 @@ bool ArticleWebView::eventFilter(QObject *obj, QEvent *ev)
if (ev->type() == QEvent::Wheel) {
QWheelEvent *pe = static_cast<QWheelEvent *>(ev);
wheelEvent(pe);
//return true;
}
if (ev->type() == QEvent::FocusIn) {
QFocusEvent *pe = static_cast<QFocusEvent *>(ev);
focusInEvent(pe);
//return true;
}
return QWebEngineView::eventFilter(obj, ev);
@ -99,13 +97,14 @@ void ArticleWebView::singleClickAction(QObject* obj, QMouseEvent * event )
if (selectionBySingleClick) {
findText(""); // clear the selection first, if any
//send dbl click event twice? send one time seems not work .weird really. need further investigate.
sendCustomMouseEvent(obj, QEvent::MouseButtonDblClick, event);
sendCustomMouseEvent(obj, QEvent::MouseButtonDblClick, event);
sendCustomMouseEvent(obj, QEvent::MouseButtonRelease, event);
}
}
void ArticleWebView::sendCustomMouseEvent(QObject* obj,QEvent::Type type,QMouseEvent * event){
QMouseEvent ev( QEvent::MouseButtonDblClick,mapFromGlobal(QCursor::pos()),mapFromGlobal(QCursor::pos()),QCursor::pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers(), Qt::MouseEventSynthesizedByApplication );
QMouseEvent ev( type,mapFromGlobal(QCursor::pos()),mapFromGlobal(QCursor::pos()),QCursor::pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers(), Qt::MouseEventSynthesizedByApplication );
QApplication::sendEvent(obj, &ev );
}