[COLOR="Blue"]
// Also tried with - Qt::Key_SysReq
QKeyEvent keydownEvent(QEvent::KeyPress, Qt::Key_Print,
Qt::AltModifier);
QDesktopWidget * desktopWidget = qApp->desktop();
qApp->sendEvent(desktopWidget, &keydownEvent);
bool bDownAccepted = keydownEvent.isAccepted();
QKeyEvent keyupEvent(QEvent::KeyRelease, Qt::Key_Print,
Qt::AltModifier);
QApplication::sendEvent(desktopWidget, &keyupEvent);
bool bUpAccepted = keyupEvent.isAccepted();
[/COLOR]
Here my assumption was that this code should send an "Alt +
PrintScreen" button press to the desktop widget which in effect should
dump the "active window image" to the ClipBoard. But it is not
happening in my case.
There is nothing copied to the ClipBoard and also bDownAccepted ,
bUpAccepted value is always false which means that DesktopWidget is
not accepting the event.
My aim is just to capture the image of active window on the screen
using QT.
can anybody tell whats wrong with the above code.
Any help would be appreciated.
Thnx in advance.
Shalabh
> Hi all,
> I want to send a KeyDown message to the desktop widget which i got
> through QApplication::desktop(). Here is the code snippet:
>
> [COLOR="Blue"]
>
> // Also tried with - Qt::Key_SysReq
>
> QKeyEvent keydownEvent(QEvent::KeyPress, Qt::Key_Print,
> Qt::AltModifier);
> QDesktopWidget * desktopWidget = qApp->desktop();
>
> qApp->sendEvent(desktopWidget, &keydownEvent);
>
> bool bDownAccepted = keydownEvent.isAccepted();
> QKeyEvent keyupEvent(QEvent::KeyRelease, Qt::Key_Print,
> Qt::AltModifier);
> QApplication::sendEvent(desktopWidget, &keyupEvent);
> bool bUpAccepted = keyupEvent.isAccepted();
>
> [/COLOR]
Don't know, but *may* be related to below:
> Here my assumption was that this code should send an "Alt +
> PrintScreen" button press to the desktop widget which in effect should
> dump the "active window image" to the ClipBoard. But it is not
> happening in my case.
> There is nothing copied to the ClipBoard and also bDownAccepted ,
> bUpAccepted value is always false which means that DesktopWidget is
> not accepting the event.
I would steer clear of ALT+SysRQ as adding one more key generates emergency
signals to the linux kernel (eg Alt+SysRQ+b reboots hard, no disk sync,
nothing, unless SysRQ handling is disabled).
Wondering if that is preventing the keypresses from getting to the
application or not.
What about PrintScreen+Shift or Ctrl - does that work?
Cheers
Tim
Sending a QEvent to the QDesktopWidget instance does nothing (well it
calls QWidget::event, which calls QWidget::keyPress/ReleaseEvent, which
does nothing by default). That Alt+PrintScreen etc. make screenshots is a
feature of the shell, not of the QDesktopWidget class :)
If you want to make a screenshot of your desktop, use QPixmap::grabWidget
or QPixmap::grabWindow.
Volker