Results 1 to 4 of 4

Thread: Putting static controls on top of QGraphicsView

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Putting static controls on top of QGraphicsView

    Hey guys.
    I got a rather simple question.

    I have a QGraphicsView set up. Now I want to have some controls, e.g. QPushButton, on top of the QGraphicsView. The control should not change its size when the QGraphicsView is being scaled and the control should also not move along, when the graphics view is being dragged/scrolled aside. So it should be something like Google Maps (you know, where the Zoom and the Map/Hybrid/Satellite-buttons are always on top?)

    I'm not quite sure what is the best way to achieve this o.O
    Can anyone give me a tiny hint or something? It's not like there's some QZAxisLayout or something, lol

  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: Putting static controls on top of QGraphicsView

    No, usually this is done by placing the desired widget(s) manually (without any layout), in the positions you want them to appear.
    The position can be set with move on setGeometry.

    For example, you can show a button at (10,10) - view coordinates by moving it to that position. The button will keep its relative position as long as the view and its parents don't change their relative positions within the main window.

    Regards
    Last edited by marcel; 9th September 2007 at 14:19.

  3. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Putting static controls on top of QGraphicsView

    You can add QPushButton on top of QGraphicsView.

    Only thing is you need to change the position of QPushButton in
    scrollContentsBy( int dx, int dy) means whenever you move scroll forward then you need to move Your pushbutton with dx.

    similarly when ever you do scale you need to do reveres scaling of PushButton.

    Some time back I did same thing with QLineEdit. and it was look like LineEdit are stable on one place.


  4. #4
    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: Putting static controls on top of QGraphicsView

    Quote Originally Posted by rajesh View Post
    You can add QPushButton on top of QGraphicsView.

    Only thing is you need to change the position of QPushButton in
    scrollContentsBy( int dx, int dy) means whenever you move scroll forward then you need to move Your pushbutton with dx.

    similarly when ever you do scale you need to do reveres scaling of PushButton.

    Some time back I did same thing with QLineEdit. and it was look like LineEdit are stable on one place.

    But it's easier to just add a widget on top of the view and adjust the position manually. Thin of it like a floating widget with a fixed relative position.

    Regards

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12

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
  •  
Qt is a trademark of The Qt Company.