问题
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