我试图在ScrollHandDrag
打开时更改QGraphicsView
的光标,但似乎不起作用。 我可以改变光标如果我禁用ScrollHandDrag
但不能同时是活跃的,我看不出有什么我可能是做错了什么......在QGraphicsView中更改光标
贝娄是重现该问题的代码的一部分:
QApplication app(argc, argv);
QGraphicsScene scene;
QRect rectangle(-8, -4, 100, 100);
QPen pen(Qt::blue, 1, Qt::SolidLine);
scene.addRect(rectangle, pen);
scene.setBackgroundBrush(Qt::white);
QGraphicsView vue(&scene);
vue.setFixedSize(250, 250);
//vue.setDragMode(QGraphicsView::ScrollHandDrag);
vue.setCursor(Qt::CrossCursor);
vue.show();
return app.exec();
有没有让光标变为默认值的函数?我尝试过这样的事情:'void MyQGraphicsView :: mouseReleaseEvent(QMouseEvent * event) {0} {QGraphicsView :: mouseReleaseEvent(event);如果(m_click) viewport() - > setCursor(Qt :: CrossCursor);如果(m_click) } else { viewport() - > unsetCursor(); } }'而不是有一个手形光标,这是我所期望的,我有箭头光标。我的问题是:我是否必须设置所有不同的游标,或者是否有一个函数可以撤销setCursor? – Leo
@Leo您可以完全注释掉'enterEvent',然后更改'mouseReleaseEvent',使其具有'viewport() - > setCursor(Qt :: OpenHandCursor);'。 – Anthony
不错的解决方法 – Chris