我在MianWindow上有两个PushButton,名为 CreateEvent , Rcreate ,我想执行on_CreateEvent_pressed() CreateEvent 按钮的事件当我< em>按 Rcreate 按钮。
我在Source下面使用但它不起作用。 感谢
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 */
}
}
答案 0 :(得分:0)
您只需调用QPushButton对象的click()插槽即可。