Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to send message to Desktop Widget

119 views
Skip to first unread message

Ansh

unread,
Apr 17, 2007, 8:38:03 AM4/17/07
to
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]

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

Tim

unread,
Apr 17, 2007, 8:44:28 AM4/17/07
to
Ansh wrote:

> 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

Volker Hilsheimer

unread,
May 23, 2007, 7:02:44 AM5/23/07
to
"Ansh" <shalabh...@gmail.com> wrote in message
news:1176813483.2...@y80g2000hsf.googlegroups.com...


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

0 new messages