Results 1 to 4 of 4

Thread: Highligt QGraphicsItem on mouse enterevent.

  1. #1
    Join Date
    Jun 2010
    Location
    Italy
    Posts
    10
    Qt products
    Platforms
    Unix/X11 Windows

    Default Highligt QGraphicsItem on mouse enterevent.

    Hi all,
    I had implemented the following object :

    class BaseEntity(QtGui.QGraphicsItem):

    and overwrite the following method:

    def hoverEnterEvent(self, event):
    self.setHiglight() #this is my function to define the color
    self.update()

    def hoverLeaveEvent(self, event):
    self.setColor() #this is my function to define the color
    self.update()

    this way dose not work very well if I have some boundingRect() that intersect.

    For exsample in case of two circle if I define a circle of radius 10 in position 0,0
    and then a circle radius 20 in position 0,0,
    the first circle is not higlited when I pass over it with the mouse ..

    I try to set the QtGui.QGraphicsItem.ItemClipsToShape flag ... but it do not work at all ..


    any idea on how to solve the this problem ?

    Regards,
    Matteo

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Highligt QGraphicsItem on mouse enterevent.

    You need to enable hover events for your item - QGraphicsItem::setAcceptHoverEvents() and reimplement QGraphicsItem::shape() for your item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2010
    Location
    Italy
    Posts
    10
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Highligt QGraphicsItem on mouse enterevent.

    Thanks,

    It works very well now as you can see at :
    http://www.youtube.com/user/pythonca.../0/VB3D9yh-MFI


    But this introduce me a problem releted to the scene mousePresEvent.
    this is my function ..on the qtscene:

    def mousePressEvent(self, event):
    qtItem=self.itemAt(event.scenePos()) #
    if qtItem:
    print "item : ", qtItem
    else:
    print "No item selected"

    sometimens and I can't understand why, if the entity is highligted this function print the "No item selected"..

    I olso add the setSelected(True) at the item douring the hoverEnterEvent...and of course
    self.GraphicsItemFlags(QtGui.QGraphicsItem.ItemIsS electable) douring init ..

    Any idea?

    Regards,
    Matteo

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Highligt QGraphicsItem on mouse enterevent.

    If an item can't be found at position you expect it to be at then most often this is the case of incorrect implementation of boundingRect() or shape().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. mouse events handling with QGraphicsItem
    By trallallero in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2009, 14:15
  2. Qgraphicsitem grabbed with mouse.
    By repka3 in forum Qt Programming
    Replies: 0
    Last Post: 31st August 2009, 14:34
  3. QGraphicsItem mouse out of focus
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 11:45
  4. mouse tracking in QGraphicsItem
    By christina123y in forum Qt Programming
    Replies: 10
    Last Post: 9th March 2009, 08:23
  5. QGraphicsItem mouse events
    By zgulser in forum Qt Programming
    Replies: 13
    Last Post: 11th February 2009, 11:19

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.