Qt:自动鼠标单击X,Y位置,使用QCoreApplication :: sendEvent(this,& click);不管用

时间:2012-07-25 07:23:19

标签: qt

我在MianWindow上有两个PushButton,名为 CreateEvent Rcreate ,我想执行on_CreateEvent_pressed() CreateEvent 按钮的事件当我< em>按 Rcreate 按钮。

我在Source下面使用但它不起作用。 感谢

mainwindow.cpp

void MainWindow::on_CreateEvent_clicked()
{
 QMessageBox::information(this,"Mouse Clicked", "This is Mouse Clicked Event");
}


void MainWindow::on_CreateEvent_pressed()
{
 QMessageBox::information(this,"Mouse Pressed", "This is Mouse Pressed Event");
}

void MainWindow::on_Recreate_pressed()
{
 QPoint pos(95,35); /* Button Position to CreateEvent Log  */
 {
  QMouseEvent click(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
  click.setAccepted(true);
  QCoreApplication::sendEvent(this, &click); /* Tried with ui->CreateEvent also */
 }
 {
  QMouseEvent click(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
  click.setAccepted(true);
  QCoreApplication::sendEvent(this, &click); /* Tried with ui->CreateEvent also */
 }
}

1 个答案:

答案 0 :(得分:0)

您只需调用QPushButton对象的click()插槽即可。