PDA

View Full Version : How to Disable Scroll Bar of QGraphicsView (or QWidget) ??



jiapei100
20th June 2010, 11:53
Hi, all:

I successfully load an image in QGraphicsView.
However, I'd love to show it without scrolling bar because I can ensure the size of the image is just equal to the size of the Widget view (I'm using the widget QGraphicsView).

But, it seems whenever I tried to load an image, the scroll bar will automatically jump out to show "I(the scroll bar )'m here". How can I disable this scroll bar?

BTW:
An image is attached and the red curves show the scroll bar which is not what I expected.
Before I load an image (or image sequence), there is no such kind of bar.



Best Regards
JIA Pei

SixDegrees
20th June 2010, 12:27
QGraphicsView inherits QScrollArea; use QScrollArea's scrollBarPolicies to set scrollbar behavior.

jiapei100
20th June 2010, 16:02
Hi, Thanks for your prompt reply.

I added these two lines

this->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
this->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );

in the class constructor of my own class CqtImageView, which inherits from QGraphicsView.
class CqtImageView : public QGraphicsView
{
}

Unfortunately, things become even worse.
This time, before loading an image (sequence), the view already shows the scroll bar !!

So, really, have you got any demo code for this issue?

Best Regards
JIA




QGraphicsView inherits QScrollArea; use QScrollArea's scrollBarPolicies to set scrollbar behavior.

SixDegrees
20th June 2010, 16:14
My code is no different (although you don't need the "this->" bit, but it shouldn't make any difference); on Linux, it turns the scrollbars off.

jiapei100
20th June 2010, 17:22
Hi, after a thorough rebuilding, now everything works fine.

Thank you so much.

Best Regards
JIA

yodreuc
6th November 2011, 03:45
Hi jiapei100!

I'm a newbie in Qt but I've read enough articles in order to efficiently remove scroll bars.

In my main class I have set the main window to occupy the whole screen as soon as the application start using the following code, mainWindow is my widget:

mainWindow.showFullScreen(); // in this case no scroll bars will appear because the app's window is already in full screen, no need to rebuild again and again

Then in my implementation file I have done this:

ui->graphicsView->setSceneRect(this->frameGeometry()); // set the scene's bounding rect to rect of mainwindow
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;