Qt - QGraphicsView without ScrollBar

后端 未结 2 1515
执念已碎
执念已碎 2021-02-04 16:59

I am trying to show a picture in it\'s full view using QGraphicsScene. But when ever I put the QgraphicsScene inside the QGraphicsView, I am getting a scroll bar. I tried so man

2条回答
  •  余生分开走
    2021-02-04 17:54

    You might be getting scrollbars because the scene is larger than the usable area within the graphics view. By default, a QGraphicsView comes with a 1-pixel margin. To fix this, you can try:

    QRect rcontent = graphicsView.contentsRect();
    graphicsView.setSceneRect(0, 0, rcontent.width(), rcontent.height());
    

    I had been getting scrollbars because I was manually setting the scene rect to the size of the graphics item I was adding -- which was as large as the QGraphicsView widget. I wasn't taking into account the margin.

提交回复
热议问题