Results 1 to 5 of 5

Thread: How to keep parts of a QGraphicsScene in view at all times, when scrolling

  1. #1
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Question How to keep parts of a QGraphicsScene in view at all times, when scrolling

    Hi all

    For a “tracker” style music interface I have a QGraphicsView for entering and editing patterns of notes – I have attached a picture for a visual aid It is not that far removed from a spreadsheet.

    Similarly to a spreadsheet, I would like to keep the “TrackHeader” and the “LineNumberColumn” in view at all times (respectively, the horizontal bar with the LEDs, and the vertical bar with the series of numbers).

    That is, when scrolling horizontally or vertically, the TrackHeader and LineNumberColumn should stay visible, while still scrolling in one axis (i.e. the LineNumberColumn will scroll through the numbers to match up with the main grid, and the TrackHeader will scroll through the tracks to match up with the tracks in the main grid.)

    Currently they both disappear if you scroll, as shown in the second image attached. I need to make them “fixed” parts of the scene in a sense. I wonder what might be the best way to go about it?

    Thanks for any advice,
    Neil
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to keep parts of a QGraphicsScene in view at all times, when scrolling

    The best way to do this is to use QGraphicsView::setViewportMargins( left, top, 0, 0 ), where left is the width of the LineNumberColumn and top is the height of the header. Then you should implement the line number and the header as widgets that stay attached to the graphics view ( just like the scroll bars do ).

    Thus way scrolling will not affect the two widgets.

  3. The following user says thank you to marcel for this useful post:

    nmather (21st April 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: How to keep parts of a QGraphicsScene in view at all times, when scrolling

    Thanks Marcel, I was able to achieve what I wanted using your suggestion.

    The two widgets do scroll in one direction each, so in their paintEvents I get the GraphicsView's scrollbar positions and paint the widgets based on this position.

    It feels a bit hackish, as the widget has to selectively paint itself based on the scrollbar position; I would rather it didn't have to worry about that, i.e. it just paints itself, and some item "viewing" it decides which portions of it to show. I may try making those two widgets in the margins inherit from AbstractScrollAreas at some point, but it works fine for now
    Qpsycle -- open-source modular music studio built with Qt

  5. #4
    Join Date
    Mar 2006
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to keep parts of a QGraphicsScene in view at all times, when scrolling

    I believe it would be much better to buid that with a Model/View, subclassing TableModelView to make custom painting.

  6. #5
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: How to keep parts of a QGraphicsScene in view at all times, when scrolling

    Hi mr.costa

    That occurred to me too, but two things stopped me trying it:

    a) The central area has quite a lot of paint operations and moving items, as well as area selection -- I wasn't sure if doing all that in widget paint events would be efficient (Would be a problem?)

    b) I'd already done most of the work in a QGraphicsView, so had a legacy system to contend with!

    Someday when I get time to go back to it I want to try different methods with it.
    Qpsycle -- open-source modular music studio built with Qt

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.