Results 1 to 3 of 3

Thread: Widget collision in QGraphicsScene

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Widget collision in QGraphicsScene

    Hi, I'm new to Qt.

    So, I'm having an issue that I can't find a way to solve. Let me explain my code:

    I have a QWidget called Table. Inside this widget there's a QGraphicsView and a QGraphicsScene inside the QGraphicsView.

    I am adding QWidgets called Item to this QGraphicsScene.

    First, I wanted to make this Item QWidget transparent, so I used:
    item->setAttribute(Qt::WA_TranslucentBackground);

    That worked fine! But, I also wanted for the collision detection in the GraphicsScene and the mouse events of this Item widget to ignore the transparent areas. I tried:
    item->setAttribute(Qt::WA_TransparentForMouseEvents);

    But, that changed nothing. The QWidget is transparent, but it is still detecting all the widget rect. How to fix it?

    Thanks.

  2. #2
    Join Date
    Nov 2012
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget collision in QGraphicsScene

    Ok guys, I was able to fix it, but I had to redo a lot of things.

    Instead of directly adding the QWidget to the QGraphicsScene, now I'm adding it to a QGraphicsProxyWidget.
    The QGraphicsProxyWidget implements the mouseMove correctly once I extend the shape() function.

    In the shape() function, this is what I have to fix it:

    QPainterPath newShape;
    newShape.addRegion( QRegion( imageInsideMyWidget.createHeuristicMask()) );
    return newShape;

    (of course, I'm doing this just once because createHeuristicMask seems quite expensive).

    So, that's it:
    QPainterPath TableItemDecorator::shape() const
    {
    return itemShape;
    }

    Fixed.

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

    amleto (21st November 2012)

  4. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget collision in QGraphicsScene

    well done and nice solution
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Move function for widget won't works in QGraphicsScene
    By alizadeh91 in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2012, 09:43
  2. Replies: 1
    Last Post: 24th May 2011, 17:29
  3. Access to custom widget functions in a QGraphicsScene
    By meazza in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2011, 09:21
  4. Stopped widget in a moveable QGraphicsScene
    By jano_alex_es in forum Newbie
    Replies: 3
    Last Post: 4th February 2011, 10:05
  5. Collision detect in QGraphicsScene
    By sophister in forum Qt Programming
    Replies: 6
    Last Post: 5th December 2009, 01:38

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
  •  
Qt is a trademark of The Qt Company.