Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.4.3
-
None
Description
When a QWidget is embedded in QGraphicsView using a QGraphicsProxyWidget, QWidget is not able to reliably setCursor. Using the example code many calls to setCursor can be made, but a cursor change is not carried out until you hover over the edges of the embedded QWidget in QGraphicsView.
#include <QtGlobal> #include <QtDebug> #include <QGraphicsScene> #include <QApplication> #include <QGraphicsView> #include <QGraphicsWidget> #include <QMessageBox> #include <QMenu> #include <QCursor> #include <QGraphicsLinearLayout> #include <QGraphicsProxyWidget> class QtWidget : public QWidget { public: QtWidget() { resize(30, 150); setMinimumSize(30,150); setMouseTracking(true); } protected: void paintEvent ( QPaintEvent * event ) { QPainter painter(this); QRect r = rect(); painter.drawLine(r.left(), r.top(), r.right(), r.bottom()); painter.drawLine(r.left(), r.bottom(), r.right(), r.top()); } void mouseMoveEvent (QMouseEvent * event) { qDebug() << "mouseMoveEvent"; if (event->y() > 75) { setCursor(Qt::IBeamCursor); setCursor(Qt::IBeamCursor); } else { setCursor(Qt::WaitCursor); setCursor(Qt::WaitCursor); } } }; class Widget : public QGraphicsWidget { public: Widget() { QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(this); lay->setOrientation(Qt::Horizontal); lay->setContentsMargins(0, 0, 0, 0); lay->setSpacing(4); lay->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); setLayout(lay); QGraphicsProxyWidget* proxy = new QGraphicsProxyWidget(this); proxy->setWidget(new QtWidget()); lay->addItem(proxy); } protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->drawRect(rect()); } }; int main(int argc, char **argv) { QApplication app(argc, argv); QGraphicsScene scene; Widget *widget = new Widget; scene.addItem(widget); QGraphicsView view(&scene); widget->resize(750, 150); view.resize(760, 160); view.show(); return app.exec(); }