PDA

View Full Version : How can I subclass QDesktopWidget to capture mousePressEvents?



amitkc
5th May 2011, 15:48
Hi all,

I want to capture portions of the screen outside my applications screen real estate. I can see how to do this as long as I can get the user to click on the screen and can store the points he selects.

But when I consider overriding mousePressEvent in a QDesktopWidget subclass I run into what I think is a problem: no public constructor for latter shown in the docs.

This makes me think I'm heading off track....any suggestions much appreciated.

Regards,
Amit

high_flyer
5th May 2011, 17:05
The desktop widget is only a widget that allows you to get some information about the screens, usually used for multi screen displays.
However, this widget does not receive input events out side the applications windows - so if you click on the desktop, you will not get a mousePressEvent on your desktop widget, which is probably why the trolls made its ctor private.
I guess the trolls should add this part to the documentation, as it pops up every now and again.
If you need to know where the user clicked out side the area of your application windows (i.e on the desktop) you will have to use native API for that.
There are some posts on this forum, and google can help you with that as well.

amitkc
5th May 2011, 17:31
Appreciate the suggestion. Don't fancy the native route so am installing the image of ~ 90% of the screen onto a QLabel sub-class and will pick up crop dimensions from the user there - via the mousePressEvents. It won't give me full screen but it probably meets my needs.

high_flyer
6th May 2011, 08:36
Do you mean you want to display a QLabel on the desktop so that the user doesn't know its not the desktop?

amitkc
6th May 2011, 16:30
Not really. It's a screen grab I'm doing. There's a tiny widget at the top of the screen - has 3 buttons and a border. Click 1 and you get a QLabel with a pixmap which shows whatever is on the screen between x1,y1 & y1,y2 where the values are chosen to bring back ~ 90% of the screen. Button 3 calls getSaveFileName to save pixmap to png file. Button 2 is supposed to allow for optional cropping of the pixmap, prior to clicking to save. 1 & 3 work; just need to look at the logic to capture the user clicks for top left, bottom right on QLabel. I think I can do this with the mousePressEvent's, some simple signals and a wee bit of logic.

ChrisW67
7th May 2011, 21:56
Since you are reinventing a wheel, you could look at how others have implemented something similar:
http://lightscreen.svn.sourceforge.net/viewvc/lightscreen/trunk