//我们通过类型转换来获得颜色 color = qvariant_cast<QColor>(event->mimeData()->colorData()); update(); } void RectItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) { Q_UNUSED(event) dragOver = false; update(); } #include "MyItem.h" #include "RectItem.h" #include <QtWidgets>...
dragOver=false;if(event->mimeData()->hasColor())//我们通过类型转换来获得颜色color = qvariant_cast<QColor>(event->mimeData()->colorData()); update(); }voidRectItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) { Q_UNUSED(event) dragOver=false; update(); } #include"MyItem.h"#in...
bool QgraphicsViewTestGUI::eventFilter(QObject* watched, QEvent* event) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseevent = static_cast<QMouseEvent*>(event); if(mouseevent->button() == Qt::LeftButton && watched == ui->graphicsView_LeftImage->viewport()) ...
我在用 void QGraphicsItem::installSceneEventFilter(QGraphicsItem * filterItem); 在QgraphicsItem上设置事件筛选器(请参阅) 现在,对于其中一些项目,我想限制移动,即更改项目的x和y位置,以便用户在对象移动的某个区域受到限制。我首先尝试用以下方式修改事件: (static cast <QGraphicsSceneMouseEvent*>(event)...