【问题标题】:event providing to QWidget(QWT) embedded into QML Qt4事件提供给嵌入到 QML Qt4 中的 QWidget(QWT)
【发布时间】:2012-11-10 12:08:09
【问题描述】:

我在 QML 项目 (Qt 4.8) 中使用了 QwtPlot (Qwt 6.0.1)。我通过 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
    }

但是,鼠标事件不能正常工作。例如,当我想绘制一个缩放矩形时,当我释放鼠标按钮时,它不会缩放,直到按下回车键。右键根本不起作用。

如何进行适当的活动提供?

【问题讨论】:

    标签: qt qml qwidget qwt


    【解决方案1】:

    在研究this issue 时,我对QDeclarativeItemQGraphicsItem 继承鼠标事件的一般印象与“正常”QWidget 事件的行为不太一样。很难在没有进一步测试的情况下具体/确定,但我有一个想法(来自 QtQuick 和 QML 之前 Qt 的遥远记忆)对于 QWidget 鼠标移动事件,您将得到一个终止 mouseMoveEvent 而没有按下 buttons() ,而在QGraphicsItem 中,您将获得鼠标移动完成的唯一通知是mouseReleaseEvent

    如果您的 GraphWidget 组件依赖于 mouseMoveEvent 并且所有按钮都打开但没有得到一个,这似乎可以解释您观察到的行为......但我不知道如何使用这些信息来修复问题抱歉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 2017-08-31
      相关资源
      最近更新 更多