当我选择几个QGraphicsItem(使用Ctrl键)时,我可以将它们一起移动,但只为实际接收事件的项目触发mouseMoveEvent。有没有办法让每个选定的项目都能收到活动?我无法在Qt的文档中找到它。同时触发几个QGraphicsItem的鼠标移动事件
我可以将选定的项目组合在一起并在QGraphicsView的mouseMoveEvent中处理它吗?
非常感谢任何帮助:)
当我选择几个QGraphicsItem(使用Ctrl键)时,我可以将它们一起移动,但只为实际接收事件的项目触发mouseMoveEvent。有没有办法让每个选定的项目都能收到活动?我无法在Qt的文档中找到它。同时触发几个QGraphicsItem的鼠标移动事件
我可以将选定的项目组合在一起并在QGraphicsView的mouseMoveEvent中处理它吗?
非常感谢任何帮助:)
没有没有默认的方式做你想做的,据我所知。有些事情,你可以做的是以下情况:
QGraphicsScene
贯彻mouseMoveEvent
itemAt
功能isSelected
),获取场景中的所有选定项目。示例代码如下:
void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
QPointF mousePosition = mouseEvent->scenePos();
QGraphicsItem* pItem = itemAt(mousePosition.x(), mousePosition.y());
if (pItem == NULL)
{
QGraphicsScene::mouseMoveEvent(mouseEvent);
return;
}
if (pItem->isSelected() == false)
{
QGraphicsScene::mouseMoveEvent(mouseEvent);
return;
}
// Get all selected items
QList<QGraphicsItem *> items = selectedItems();
for (unsinged i=0; i<items.count(); i++)
// Do what you want to do when a mouse move over a selected item.
items[i]->doSomething();
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
我你的问题一点点的字里行间,但它听起来像是你可能会在你的QGraphicsItem
类(ES)实施QGraphicsItem::itemChange
得到更好的服务。只要位置发生变化,就会调用它 - 无论是通过鼠标,键盘,编程等。如果需要,甚至可以取消更改。