Results 1 to 6 of 6

Thread: How can I subclass QDesktopWidget to capture mousePressEvents?

  1. #1
    Join Date
    Jan 2007
    Location
    Hampton, Middlesex, UK
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How can I subclass QDesktopWidget to capture mousePressEvents?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I subclass QDesktopWidget to capture mousePressEvents?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    amitkc (5th May 2011)

  4. #3
    Join Date
    Jan 2007
    Location
    Hampton, Middlesex, UK
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I subclass QDesktopWidget to capture mousePressEvents?

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can I subclass QDesktopWidget to capture mousePressEvents?

    Do you mean you want to display a QLabel on the desktop so that the user doesn't know its not the desktop?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #5
    Join Date
    Jan 2007
    Location
    Hampton, Middlesex, UK
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I subclass QDesktopWidget to capture mousePressEvents?

    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.

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can I subclass QDesktopWidget to capture mousePressEvents?

    Since you are reinventing a wheel, you could look at how others have implemented something similar:
    http://lightscreen.svn.sourceforge.n...htscreen/trunk

Similar Threads

  1. QDesktopWidget initialization
    By drweilert in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2011, 19:42
  2. QDockWidget & QDesktopWidget
    By winkle99 in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2010, 23:26
  3. Replies: 3
    Last Post: 5th July 2009, 17:22
  4. QDesktopWidget
    By ToddAtWSU in forum Qt Programming
    Replies: 0
    Last Post: 3rd July 2008, 13:31
  5. QDesktopWidget Screenshot && Mouse grab
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th March 2007, 10:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.