PDA

View Full Version : Putting static controls on top of QGraphicsView



durbrak
9th September 2007, 13:35
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 :)

marcel
9th September 2007, 14:02
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

rajesh
10th September 2007, 12:01
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.

marcel
10th September 2007, 12:51
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