event providing to QWidget(QWT) embedded into QML Qt4

£可爱£侵袭症+ 提交于 2019-12-10 22:25:41

问题


I've used QwtPlot (Qwt 6.0.1) in QML project (Qt 4.8) . i'm wrap it via 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);
}

and insert into into QML via code

qmlRegisterType<GraphWidgetQML> ("GraphWidget",1,0,"GraphWidget"); //registration type

and 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
    }

But, Mouse evets won't work correctly. For example when i want to draw a zooming rectangle, when i released the mouse button it won't zoom untill press enter key. Right button doesn't work at all.

How to make proper event providing?


回答1:


While researching this issue I got the general impression QDeclarativeItem's QGraphicsItem-inherited mouse events don't behave quite the same as the "normal" QWidget events. Hard to be specific/sure without further testing, but I have an idea (from distant memory of Qt before QtQuick & QML) that for QWidget mouse move events, you'll get a terminating mouseMoveEvent with no buttons() pressed, whereas in QGraphicsItem the only notification you'll get the mouse-move has finished is a mouseReleaseEvent.

It would seem to explain your observed behaviour if your GraphWidget component was relying on a mouseMoveEvent with all buttons up but not getting one... but I've no idea how this information can be used to fix the issue sorry.



来源:https://stackoverflow.com/questions/13321902/event-providing-to-qwidgetqwt-embedded-into-qml-qt4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!