上一篇我们根据实际使用提出了事件过滤器的需求,那么现在就部署吧,首先
#include "mycapture.h"
#include <qapplication.h>
#include <qpainter.h>
#include <qstring.h>
#include <qtimer.h>
#include <chrono>
ScreenCaptureWidget::ScreenCaptureWidget(QWidget* parent) : QWidget(parent)
{
// 确保接收鼠标事件
setMouseTracking(true);
m_lastClickTime = 0;
m_clickCount = 0;
m_lastRightClickTime = 0;
m_rightClickCount = 0;
m_clicknum = 0;
}
bool ScreenCaptureWidget::eventFilter(QObject *o, QEvent *e)
{
if (!o ||!e)
return true;
if (o == this && e->type() == QEvent::MouseButtonPress)
{
int interval = QApplication::doubleClickInterval();
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
if (mouseEvent->button() == Qt::LeftButton)
{
auto currentTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
long long atime = currentTime - static_cast<long long>(m_lastClickTime);
if (currentTime - static_cast<long long>(m_lastClickTime) < static_cast<long long>(QApplication::doubleClickInterval()))
{
qDebug("the mouse default interval (%d).", QApplication::doubleClickInterval());
m_clickCount++;
}
else
{
m_clickCount = 1;
}
m_lastClickTime = currentTime;
m_clicknum++;
qDebug("The mouse two interval (%lld) It is the (%d) times.", atime, m_clicknum);
if (m_clickCount == 1)
{
Q

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



