Results 1 to 7 of 7

Thread: Retrieving offsets of scroll in QWorkspace

  1. #1
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Retrieving offsets of scroll in QWorkspace

    This question is regarding QT4.

    I am using QWorkspace to implement an MDI application. The app is a database design tool, and I am using the windows in the QWorkspace to represent DB tables. I am painting on the background to represent relations between the tables. Everything works fine except when the workspace is scrolled. First of all, I draw my relations based on "pristine" coordinates, so the relations do not scroll with the tables. Second, when I want to save out the positions of everything, I want to save out their unscrolled positions.

    The bottom line is that I need to retrieve the current scroll state of the QWorkspace, but I cannot seem to find any way to do it. There doesn't seem to be any "scroll" signal emitted, nor anything I can trap in an eventfilter. The actual scrollbars themselves are private and inaccesible to my class which inherits from QWorkspace. I know there are nasty workarounds, but I could solve this problem very cleanly if I could simply figure out the current scroll state.

    Is there any way to retrieve the current scroll offsets in a QWorkspace?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieving offsets of scroll in QWorkspace

    What you are doing is a little unclear for me... Are you painting on QWorkspace directly? You should be using child windows (probably QScrollArea based) and it should be easy to get coordinates of their objects. Can you explain (a screenshot could be handy here)?

  3. #3
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving offsets of scroll in QWorkspace

    Quote Originally Posted by wysota
    What you are doing is a little unclear for me... Are you painting on QWorkspace directly? You should be using child windows (probably QScrollArea based) and it should be easy to get coordinates of their objects. Can you explain (a screenshot could be handy here)?
    Here's a screenshot (click to enlarge)



    Yes, I am painting directly onto the QWorkspace. Everything works fine until I scroll. When I scroll, the drawing of the lines is wrong because the drawing code has no knowledge of the scroll state (NOTE: in the screenshot there is no scrolling going on...I am talking about scrolling of the enclosing workspace, not inside of the individual child windows). The problem isn't just the drawing of the lines. I also want to save out the absolute x,y coordinates of all windows to a save file, and these numbers will be wrong if the workspace is scrolled.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieving offsets of scroll in QWorkspace

    Your approach is strange, but ok Getting the values of those scrollbars will not be easy, because they are declared as private members of QWorkspace, so you have to "hack" the access restrictions using Qt's mechanisms.

    If you look at QWorkspace source code, you'll notice, that the scrollbars are created and assigned names:
    Qt Code:
    1. d->vbar = new QScrollBar(Qt::Vertical, this);
    2. d->vbar->setObjectName(QLatin1String("vertical scrollbar"));
    3. //...
    4. d->hbar = new QScrollBar(Qt::Horizontal, this);
    5. d->hbar->setObjectName(QLatin1String("horizontal scrollbar"));
    To copy to clipboard, switch view to plain text mode 

    Now you have to get a pointer to those items using QObject::findChild (or qFindChild() if you're using MSVC):
    Qt Code:
    1. QScrollBar *vertical = workspace->findChild<QScrollBar*>(QLatin1String("vertical scrollbar"));
    2. QScrollBar *horizontal = workspace->findChild<QScrollBar*>(QLatin1String("horizontal scrollbar"));
    To copy to clipboard, switch view to plain text mode 

    Then you can fetch their values using QAbstractSlider::value().

  5. The following user says thank you to wysota for this useful post:

    hardgeus (9th May 2006)

  6. #5
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving offsets of scroll in QWorkspace

    Quote Originally Posted by wysota
    Your approach is strange, but ok
    ...
    That's it, it's working now, thanks! I agree with you that my approach is somewhat odd, but I can't think of a cleaner way to do it. This is actually my third time rewriting this app:

    http://www.hardgeus.com/projects/pgdesigner/

    I initially wrote it in FLTK, then ported it to wxWindows, and finally I'm moving it to QT. For this go-round I have made a fundamental change, which is this somewhat strange approach you see. In my initial implementations, I implemented my own widgets from the base widget classes in the APIs, but 90% of my code ended up being funky event handling, drag and drop etc. etc. I decided this time I would just use built in widgets with minor subclassing.

    I don't know if you've used Star Designor, or Microsoft's built in datamodel tool with MS SQL Server, but that's the sort of interface I'm going for. Do you have any cleaner ideas of how I could implement my widgets?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieving offsets of scroll in QWorkspace

    You could use Q3Canvas or wait for QGraphicsView when Qt4.2 is released.

    If you wish to stay with your approach, you should at least remove the decorations from child windows.

  8. #7
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieving offsets of scroll in QWorkspace

    Quote Originally Posted by wysota
    You could use Q3Canvas or wait for QGraphicsView when Qt4.2 is released.

    If you wish to stay with your approach, you should at least remove the decorations from child windows.
    Yeah, QGraphicsView seems like a really good fit. It shouldn't be too incredibly difficult to port the current code over once 4.2 is released, as I'm really letting QT handle all of the dirty work right now so my code is pretty light.

    In the meantime, by window decorations you're referring to the min/max button etc? I tried getting rid of them by setting window flags, but I couldn't get it to work.

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.