0

我在 MianWindow 上有两个 PushButton,名为CreateEventRcreate,我想在按下Rcreate按钮时执行CreateEvent按钮的 on_CreateEvent_pressed() 事件。

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

主窗口.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 */
 }
}
4

1 回答 1

0

您可以简单地调用 QPushButton 对象的 click() 插槽。

于 2012-07-25T07:34:29.877 回答