Results 1 to 5 of 5

Thread: Get QWidget pixel color below mouse Cursor

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Get QWidget pixel color below mouse Cursor

    Hi,

    Is there anyway to get the color of a pixel on a QWidget on a known pixel position?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get QWidget pixel color below mouse Cursor

    See QPixmap::grabWidget() with a proper second argument (or QPixmap::grabWindow() when it is outside your app) and then use QPixmap::toImage() and finally get the color using QImage::pixel().

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get QWidget pixel color below mouse Cursor

    Hi,

    Thanks, but is a slow solution. I need a faster way to get it.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get QWidget pixel color below mouse Cursor

    Did your widget change a lot? if not, you can cache a QImage inside the paint method and use that for determinating the color at a specific point. Beside that I don't know a solution for your problem with Qt. You can of course use the operating API to get that information.

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get QWidget pixel color below mouse Cursor

    Hi,

    Thanks Lykurg,

    Did your widget change a lot?
    Yes, it changes very fast as it shows images captured from a camera. Before you tell me to get the image pointer, I need to tell you that as there is a thread that emits signals with image pointers, this pointers can point on deleted memory. Sending copy images slows down my application a lot.

    Will take a look to use OS specific API to get it. I think that on Windows I can get the HDC pointer to get this information.

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. Replies: 6
    Last Post: 2nd March 2018, 05:39
  2. How to read a color of a pixel on a Widget?
    By wringer in forum Newbie
    Replies: 5
    Last Post: 4th December 2009, 07:31
  3. How to get pixel color from QPainter ??
    By rameshg87 in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2008, 09:58
  4. getting color from a pixel on canvas
    By teeshift in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 05:12
  5. How to get color of pixel or point by QMouseEvent
    By Krishnacins in forum Newbie
    Replies: 4
    Last Post: 28th May 2006, 02:46

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.