Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

setDragMode not working when I use setSceneRect for the QGraphicsView



  • I am using "setSceneRect" to disable the autoscaling when I drag and drop items to the view.

    but when I use it I am not able to navigate through the scene using mouse dragging.
    What am I missing and if there is a suggestion of how to get the behavior needed?

    those are the 2 lines of code used for setting the scene and allowing DragMode:

    this->setSceneRect(-150,-150,300,300);
    
    this->setDragMode(QGraphicsView::ScrollHandDrag	);
    

    the output is that I am not able to navigate by mouse in the scene


  • Lifetime Qt Champion

    Hi,

    Just a quick idea: what about disabling the scroll bars ?

    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    


  • I tried it but still, the problem exists.
    the workaround I am using right now is that I added some dummy invisible items to create an initial sceneRect without setting the sceneRect by my self so it's working but this is not a good practice at all, I need to know the right method for doing it.


Log in to reply