简体   繁体   English

Qt - 没有ScrollBar的QGraphicsView

[英]Qt - QGraphicsView without ScrollBar

I am trying to show a picture in it's full view using QGraphicsScene. 我试图用QGraphicsScene在它的全景视图中显示一张图片。 But when ever I put the QgraphicsScene inside the QGraphicsView, I am getting a scroll bar. 但是当我把QgraphicsScene放在QGraphicsView中时,我得到一个滚动条。 I tried so many ways But all are went to veins. 我尝试了很多方法但是所有的都去了静脉。 So can anybody tell me how to obtain the full view without the scrollbar. 所以有人可以告诉我如何在没有滚动条的情况下获得完整视图。

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. 默认情况下,QGraphicsView具有1像素的边距。 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. 我一直在使用滚动条,因为我手动将场景rect设置为我添加的图形项的大小 - 这与QGraphicsView小部件一样大。 I wasn't taking into account the margin. 我没有考虑到保证金。

QGraphicsView v;
v.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
v.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

To adjust the scrolling programmatically once these have been hidden, use one of the overloads of v.ensureVisible() . 要在隐藏这些滚动后以编程方式调整滚动,请使用v.ensureVisible()的重载之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM