Message transmission between qgraphicsitem neutron item and parent item

Source: Internet
Author: User

Now, you need to add a Control Point (sub-item) on the parent item to adjust the shape of the parent item.

The key is that after the sub-item is moved, you must hand over its location information to the parent item so that the parent item can update its shape.

After checking the document of QT for a long time, you need to use setfilterschildevents (true) in the parent item to set to allow blocking of all messages to the Child item, and then reload this function:

bool sceneEventFilter ( QGraphicsItem * watched, QEvent * event )
{
If (watched-> type () = qgraphicsrectitem: type) // all of my sub-items are rect
{
if(event->type() == QEvent::GraphicsSceneMouseMove)
{
// Process mobile messages
}
else if(event->type() == QEvent::GraphicsSceneMouseRelease)
{
// Process the mouse release message
}
}
Return false; // false: the message of the sub-item will still be processed. If true is returned, the message of the sub-item will not be processed.

}

Solved this problem.

When reloading an item, make sure to determine whether it is the item you want to intercept.

Or you can use

Installsceneeventfilter

To intercept messages of an item and specify the item to be filtered.

Reference: http://blog.csdn.net/fly542/article/details/6459661

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.