提供嵌入QML Qt4的QWidget(QWT)的事件

时间:2012-11-10 12:08:09

标签: qt qml qwidget qwt

我在QML项目中使用了QwtPlot(Qwt 6.0.1)(Qt 4.8)。我通过QDeclarativeItem包装它

GraphWidgetQML::GraphWidgetQML(QDeclarativeItem *parent):QDeclarativeItem(parent)
{
    _GraphArea = new GraphWidget; //child of QwtPlot without event handlers overrides
    QGraphicsProxyWidget *_wiget = new QGraphicsProxyWidget(this);    
    _wiget->setWidget(_GraphArea);
    _wiget->setFlag(QGraphicsItem::ItemIsFocusable,true);
    this->setClip(true);
}

并通过代码

插入到QML中
qmlRegisterType<GraphWidgetQML> ("GraphWidget",1,0,"GraphWidget"); //registration type

和QML

    GraphWidget {
        id: drawer

        objectName: "drawer"

        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        //
        anchors.topMargin: 5
        anchors.bottomMargin: 5
        anchors.leftMargin: 5
        anchors.rightMargin: 5
    }

但是,鼠标evet将无法正常工作。例如,当我想绘制缩放矩形时,当我释放鼠标按钮时,它将不会缩放,直到按回车键。右键根本不起作用。

如何提供适当的活动?

1 个答案:

答案 0 :(得分:0)

在研究this issue时,我得到了总体印象QDeclarativeItem的{​​{1}} - 继承的鼠标事件与“正常”QGraphicsItem事件的行为并不完全相同。没有进一步测试很难具体/确定,但我有一个想法(来自QtQuick和QML之前的Qt的远距离记忆),对于QWidget鼠标移动事件,你将获得终止QWidget没有mouseMoveEvent被按下,而在buttons()中,您完成鼠标移动的唯一通知是QGraphicsItem

如果您的mouseReleaseEvent组件依赖GraphWidget所有按钮但没有获得一个按钮,它似乎可以解释您观察到的行为......但我不知道这些信息是如何形成的用来解决问题抱歉。

相关问题