我在 MianWindow 上有两个 PushButton,名为CreateEvent和Rcreate,我想在按下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 */
}
}