Results 1 to 2 of 2

Thread: QGraphicsItem mousePressEvent only on opaque pixels

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QGraphicsItem mousePressEvent only on opaque pixels

    Hi,

    I'm trying to make my QGraphicsItem only respond to mousePressEvent's if the user clicks on opaque pixels of the item.

    How should I go about doing this?

    So far I think I have to obtain the raw pixels of the QGraphicsItem, but this seems to be very inefficient.
    (I guess I need to render the QGraphicsItem to an off scene buffer, then do a x,y pixel lookup on the buffer).

    Any ideas?

    Thanks!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem mousePressEvent only on opaque pixels

    I dont think mouse clicks are propogated for transparent pixels. But I guess you dont want clicks on semi transparent area also ?
    If yes, then you can try 2 things -
    1) Subclass QGraphicsItem and override the mousePressEvent. In that you can accept or ignore the event based on items . This is what u have posted and I too not sure how we can get a pixels value for a graphics item
    2) You can override shape() function and return the path. This function is responsible where mouse can be clicked.. read the doc

Similar Threads

  1. Replies: 9
    Last Post: 13th June 2012, 15:42
  2. QGraphicsItem focusInEvent mousePressEvent
    By medved6 in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2010, 06:15
  3. Pixels
    By Dante in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2009, 20:50
  4. Replies: 6
    Last Post: 30th April 2007, 23:59
  5. opacity of QLabel(background opaque)
    By Stephano in forum Qt Tools
    Replies: 1
    Last Post: 9th May 2006, 12:57

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.