触发了鼠标按下的事件,但没有触发鼠标移动的事件

时间:2019-09-12 12:55:19

标签: c++ qt qt3d

我正在使用Qt3D。我将QObjectPicker添加到我的3D实体中,如下所示:

Qt3DRender::QObjectPicker *MyScene::createObjectPickerForEntity(Qt3DCore::QEntity *entity)
{
    if (!entity)
        return nullptr;

    picker = new Qt3DRender::QObjectPicker(entity);
    picker->setHoverEnabled(true); // I set this correctly
    picker->setDragEnabled(true); // Also required!
    picker->setObjectName(QStringLiteral("__internal ") + entity->objectName());
    entity->addComponent(picker);
    connect(picker, &Qt3DRender::QObjectPicker::pressed, this, &MyScene::handlePickerPress);
    connect(picker, &Qt3DRender::QObjectPicker::moved, this, &MyScene::handlePickerMove);

    return picker;
}

会触发鼠标按下事件,并且相应的插槽会正确记录被按下实体的名称和全局坐标:

void MyScene::handlePickerPress(Qt3DRender::QPickEvent *event)
{
    Qt3DCore::QEntity *pressedEntity = qobject_cast<Qt3DCore::QEntity *>(sender()->parent());
    if (!pressedEntity && !pressedEntity->isEnabled())
        return;

    qDebug() << "Pressed Entity Name: "<< pressedEntity->objectName();
    qDebug() << "Global Coord: " << event->worldIntersection();
}

但是,令我惊讶的是,鼠标移动(悬停)事件不起作用。以下插槽功能不记录任何内容。另外,当我在此插槽中放置调试器断点时,我发现根本没有调用它:

void MyScene::handlePickerMove(Qt3DRender::QPickEvent *event)
{
    qDebug() << "Hover Intersection:" << event->worldIntersection();
}

我想念什么吗?


我的Qt3D渲染设置为:

m_renderSettings = new Qt3DRender::QRenderSettings();
m_renderSettings->pickingSettings()->setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);
m_renderSettings->pickingSettings()->setPickResultMode(Qt3DRender::QPickingSettings::NearestPick);
m_renderSettings->setObjectName(QStringLiteral("__internal Scene frame graph"));
m_renderer = new Qt3DExtras::QForwardRenderer();
m_renderer->setClearColor(QColor("#c8c8c8"));
m_renderSettings->setActiveFrameGraph(m_renderer);
m_renderSettings->setRenderPolicy(Qt3DRender::QRenderSettings::RenderPolicy::OnDemand);

m_rootEntity->addComponent(m_renderSettings);

m_rootEntity->addComponent(new Qt3DInput::QInputSettings());

更新

this report有关。

1 个答案:

答案 0 :(得分:3)

moved信号says的描述:“当pickAttribute属性定义的边界体积与鼠标移动并按下按钮时的光线相交时,将发出此信号”。

因此,此信号不是在悬停/鼠标移动时发出,而是在按下鼠标按钮时移动鼠标时发出。