Results 1 to 6 of 6

Thread: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??

  1. #1
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    105
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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
    Attached Images Attached Images
    Last edited by jiapei100; 20th June 2010 at 12:57.
    Welcome to Vision Open
    http://www.visionopen.com

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??

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

  3. #3
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    105
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to Disable Scroll Bar of QGraphicsView (or QWidget) ??

    Hi, Thanks for your prompt reply.

    I added these two lines
    Qt Code:
    1. this->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    2. this->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
    To copy to clipboard, switch view to plain text mode 

    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 View Post
    QGraphicsView inherits QScrollArea; use QScrollArea's scrollBarPolicies to set scrollbar behavior.
    Welcome to Vision Open
    http://www.visionopen.com

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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.

  5. #5
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    105
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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
    Welcome to Vision Open
    http://www.visionopen.com

  6. #6
    Join Date
    Nov 2011
    Posts
    5
    Qt products
    Qt3
    Platforms
    Windows

    Default 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 );

Similar Threads

  1. Replies: 0
    Last Post: 19th November 2009, 19:19
  2. How to disable vertical scroll bar in QTableWidget
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2009, 12:07
  3. QGraphicsView without scroll bar
    By sanjayshelke in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2009, 13:17
  4. Replies: 1
    Last Post: 11th June 2009, 06:49
  5. QGraphicsView : scroll on drag
    By kghose in forum Qt Programming
    Replies: 4
    Last Post: 14th August 2008, 22:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.