我有像这个问题一样的按钮的无边界表单
问题是我不能点击按钮。它仅在我执行双击而不更改按钮位置时才有效。如何检查我执行单击(而不是拖动)的用户?
代码来了:
bool LoginForm::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QMouseEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (obj == ui.loginButton)
{
QPoint absPos = ui.loginButton->mapToParent(QPoint(0, 0));
m_dragPosition = (mouseEvent->pos() + absPos);
return true;
}
}
return false;
}
void LoginForm::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
m_dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void LoginForm::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
QPoint coord = event->globalPos() - m_dragPosition;
move(coord);
event->accept();
}
}