Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - QGraphicsView without ScrollBar

Tags:

c++

qt

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 many ways But all are went to veins. So can anybody tell me how to obtain the full view without the scrollbar.

like image 740
prabhakaran Avatar asked Aug 18 '10 15:08

prabhakaran


2 Answers

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.

like image 164
AndrewS Avatar answered Sep 30 '22 03:09

AndrewS


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().

like image 20
Ken Bloom Avatar answered Sep 30 '22 03:09

Ken Bloom