Nominate our 2022 Qt Champions!

Incorrect Scene Size Dimensions when called from Custom QGraphicsWidget

  • I have the following simple setup,

    @int main(int argc, char argv[])
    QApplication app(argc, argv);
    scene = new QGraphicsScene();
    QCustomGraphicsView* customGraphicsView= new QCustomGraphicsView(scene) ;

    QCustomGraphicsWidget* customWidget = new QCustomGraphicsWidget();
    scene->addItem(customWidget) ;
    customGraphicsView->show() ;
    return app.exec();


    QCustomGraphicsView size is set within its own constructor (and is based up a larger window). It doesn't have a frame and scrollbars are disabled.

    In QCustomGraphicsWidget...

    @void QCustomGraphicsWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)

    QGraphicsWidget::mouseMoveEvent(event); // move the item...
    qDebug(&#41; << QString("Mouse Move Event"&#41; ;
    QRectF sceneRect = scene()->sceneRect() ;
    qDebug("geo: %f %f", sceneRect .width(), sceneRect .height());


    And the sceneRect variable does not return the correct size of the scene that it has been added to.

    What I am trying to do, is enforce that when my QCustomGraphicsWidget is moved around the scene that when it gets to the edge, it can't be dragged beyond that and out of sight.

Log in to reply