QGraphicsView shifted its contents when scrollbar appear

  • 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;
        QBrush brush(Qt::red);
        //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.

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


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

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

Log in to reply