How to trigger a hotkey to a QWindow using a QButton?
-
Can you show the compiler error message please ?
-
@SGaist said in How to trigger a hotkey to a QWindow using a QButton?:
Can you show the compiler error message please ?
Yes, sure.
Compile Output in Qt Creator
Detail: Changed button's name to exportBtn_2 and targetWidget to simulationWidget, but the error persists
-
Did you include QEvent ?
-
@SGaist said in How to trigger a hotkey to a QWindow using a QButton?:
Did you include QEvent ?
Yes, i do.
-
@SGaist said in How to trigger a hotkey to a QWindow using a QButton?:
Did you include QEvent ?
I got the solution. I was doing #include <xdotool-master/xdo.h> and i think this file was causing some type of conflict. I just commented this line.
I gonna back to the event's problem
-
void Simulate::on_selectAllBtn_clicked() { QKeyEvent *eventPress = new QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::ControlModifier); QKeyEvent *eventRealease = new QKeyEvent(QEvent::KeyRelease, Qt::Key_A, Qt::ControlModifier); QCoreApplication::postEvent(targetWidget, eventPress); QCoreApplication::postEvent(targetWidget, eventRealease); }
This solution doesnt work. Is this code correct? As I commented, I created a QWindow from a window ID of a external program (in case, a gedit text editor) and put it on a QWidget. I dont know if this approach is for my case. I tried too use QApplication::setActiveWIndow and targetWidget->setFocus() before, but without success. Tried send the event to QWindow too, without success.
-
You are trying to send these events to an external application ?
Which is it ? -
@SGaist said in How to trigger a hotkey to a QWindow using a QButton?:
You are trying to send these events to an external application ?
Which is it ?Kind of it. I have a gedit text editor (external application) embed to a QWindow (intern application). And a QWidget is created from this QWindow, using QWidget *widget = QWidget::createWindowContainer(window);
In addition to that widget, i have too, on GUI, a QButton, called "Select All". When user click on this button, the system should select all text in text editor. So Im trying to send a Ctrl+A under the covers.
But I dont know if Im on right way to do this using that code.
-
Which OS are you on ?
Sending key events through Qt's event loop like that won't work AFAIK. The application while embedded is still an external application.
-
@SGaist said in How to trigger a hotkey to a QWindow using a QButton?:
Which OS are you on ?
Sending key events through Qt's event loop like that won't work AFAIK. The application while embedded is still an external application.Im using Ubuntu 18.04.
There is a way to send the key event through OS?