1 Attachment(s)
How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
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
Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
QGraphicsView inherits QScrollArea; use QScrollArea's scrollBarPolicies to set scrollbar behavior.
Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
Hi, Thanks for your prompt reply.
I added these two lines
Code:
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
Quote:
Originally Posted by
SixDegrees
QGraphicsView inherits QScrollArea; use QScrollArea's scrollBarPolicies to set scrollbar behavior.
Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
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.
Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
Hi, after a thorough rebuilding, now everything works fine.
Thank you so much.
Best Regards
JIA
Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??
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::ScrollBarAlwaysO ff);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );