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. [Solved]Strange temporary Auto Scroll in QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

[Solved]Strange temporary Auto Scroll in QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.2k Views 1 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.
  • idlefrogI Offline
    idlefrogI Offline
    idlefrog
    wrote on last edited by
    #1

    When I add two items to a QGraphicsView with one moveable and the other fixed, the graphics view auto scrolls for a while as it tries to keep both items in view. Of course with a blank background the 'fixed' item seems to move too which is not what you want to see when moving just one item.
    When the 'moved item' moves outside the view window, the auto scrolling stops, and the scroll bars appear.

    Is there a way to stop this initial 'auto scroll'?

    So here's the scenario. Add two items to the scene. One FIXED at (0,0), and another at (5,5) lets say.
    Then move the one at (5,5) somewhere and the auto-scroll starts :(

    Although perhaps not too relevant, here's how I add the items to the scene:

    @
    //The moveable item
    QGraphicsRectItem *rect = new QGraphicsRectItem(0,0,100,50) ;
    rect->setFlag( QGraphicsItem::ItemIsMovable, true ) ;
    _scene.addItem( rect );

    // Some fixed item
    _scene.addItem( new QGraphicsRectItem(5,5, 25 , 25) );

    ui->graphicsView->setScene(&_scene);
    

    @

    Of course if I change the alignment one can perhaps keep the fixed item at the top left corner in the view - BUT I really want to have the centre point in the centre of the view AND for it to be FIX unless the user moves the scrollbars himself, which by the way are not visible UNTIL an item moves outside the view.

    Now, another condition is: I don't want to have the scrollbars visible by default especially if the scene is entirely visible in the view.

    This can probably be solved by just setting some simple flag, i know... BUT... I can't see it!
    Can anyone out there help?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ote13
      wrote on last edited by
      #2

      For making your scrollbars not visible if not needed this should do it :
      @setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
      setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);@

      1 Reply Last reply
      0
      • idlefrogI Offline
        idlefrogI Offline
        idlefrog
        wrote on last edited by
        #3

        For me it does not matter if the scroll bars are visible or not.
        I just want to be able to move the moveable item without the view automatically scrolling.
        That way, when the user moves the 'moveable' item, the FIXED item stays fixed within the view (and of course in the scene).
        If the user moves the scroll bars THEN and ONLY THEN should the FIXED item change position in the view.

        It should not be a function of the 'moveable' item position.

        To resolve this I may just run the debugger through the Qt source, to get a better idea as to why its 'auto scrolling'.

        1 Reply Last reply
        0
        • idlefrogI Offline
          idlefrogI Offline
          idlefrog
          wrote on last edited by
          #4

          After some debugging, and reading the documentation: The reason for this behaviour can be put down to the scene being initially smaller than the view
          According to the documentation: When the scene wholely fits in the view, the view centres the scene according to the alignment.

          There seems to be just three/four solutions to the illusion that the FIXED item is moving:

          Draw a background for the scene! (of course)

          Set the alignment to the edge of the canvas, e.g.,

          @graphicsView->setAlignment(Qt::AlignLeft | Qt::AlignTop) ;@

          A fudge solution: Set a large scene size bigger than the view and big enough for all your items.

          A fudge solution: Fill the scene with so many items that it does not fix wholely in the view. (i.e. as in the chips example)

          What would be nice is to somehow say to the scene: 'If the scene changes size, keep the view centred on some scene coordinate'.

          Any comments from anyone on this is appreciated :)

          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