Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView shifted its contents when scrollbar appear
Qt 6.11 is out! See what's new in the release blog

QGraphicsView shifted its contents when scrollbar appear

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sngqtS Offline
    sngqtS Offline
    sngqt
    wrote on last edited by
    #1

    I noticed that QGraphicsView shifted its contents by few pixels upward when scrollbar appear. Is there anyway to avoid such behavior?. I want the scrollbar appear but the contents should stay at the same position.

    Here is the sample codes:

        QApplication a(argc, argv);
    
        QGraphicsView v;
        QGraphicsScene scene;
        v.show();
    
        v.setScene(&scene);
        QBrush brush(Qt::red);
        scene.addRect(0,0,1000,80,QPen(),brush);
        //When you reduce the width of v, scrollbar appear but contents shifted upward.
        return a.exec();
    

    I will be very appreciated if someone could help.

    Joel BodenmannJ 1 Reply Last reply
    0
    • sngqtS sngqt

      I noticed that QGraphicsView shifted its contents by few pixels upward when scrollbar appear. Is there anyway to avoid such behavior?. I want the scrollbar appear but the contents should stay at the same position.

      Here is the sample codes:

          QApplication a(argc, argv);
      
          QGraphicsView v;
          QGraphicsScene scene;
          v.show();
      
          v.setScene(&scene);
          QBrush brush(Qt::red);
          scene.addRect(0,0,1000,80,QPen(),brush);
          //When you reduce the width of v, scrollbar appear but contents shifted upward.
          return a.exec();
      

      I will be very appreciated if someone could help.

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by
      #2

      The easiest solution is to always show the scrollbars, if that is acceptable:

      _myGraphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      _myGraphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      

      Otherwise I guess you won't have any other option besides manually translating the viewport.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      0
      • sngqtS Offline
        sngqtS Offline
        sngqt
        wrote on last edited by sngqt
        #3

        Thanks for your suggestion.
        How would I manually translate the view port ?
        A snippet could help. Thanks

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved