Qt : Automatic Mouse Click on X,Y position, using QCoreApplication::sendEvent( this, &click); is not Working.
-
I have Two PushButton on MianWindow, named CreateEvent and Rcreate, I want to Execute on_CreateEvent_pressed() Event of CreateEvent button when i press Rcreate Button.
I used below Source but its not working.
Thanks
@
mainwindow.cppvoid 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 */
}
}@
-
try it :
@
installEventFilter(this);
@for enable the event filter on MainWindow .
-
I added it here but still its not working...
@
void MainWindow::on_Recreate_pressed()
{
installEventFilter(this);
@on other hand i tried with the local position of ui->????, then its woks....
@
void MainWindow::reCreate(QObject button) / button = ui->???????? */
{QPoint pos(1,1); /* Local Button Position on main window */
{
QMouseEvent click(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
click.setAccepted(true);
QCoreApplication::sendEvent(button, &click);
}
{
QMouseEvent click(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
click.setAccepted(true);
QCoreApplication::sendEvent(button, &click);
}
}@
But I Want to work with global position for ui->???? as i explained earlier...
Thanks @ regards.
-
Do you seriously want to hardcode widget positions? I can see no reason whatsoever to do so, maybe with the one exception of testing the UI (and even that is a bad idea).
Why don't you just connect the signals of the Rcreate button to some slots that trigger the functionality you wan?