PDA

View Full Version : Anchor widgets in QGraphicsScene



johnsoga
16th February 2010, 20:27
I am trying create a multitouch game table with a control area for each player and the game master.

4298

I want to have a graphics scene that contains the map and can be zoomed in and out and translated. I think I also need the control widgets in the scene because I want to rotate them according to the side of the table they are on. I am wondering if there is a way to anchor the widgets around the QGraphicsView according to the picture and not have them move or change size when I zoom or translate the QGraphicsView.

johnsoga
17th February 2010, 21:33
I think I figured out a solution. I created a QGraphicsView and added a QGraphicsScene that contained the control widgets. Then I created another QGraphicsView with a QGraphicsScene that contains the map I want to display. I then add the QGraphicsView with the map to the QGraphicsScene with the controls and set it below the control widgets. Now I can scroll and zoom my map yet keep my control widgets in place with the correct orientation. Does anyone see an issue with this method?

aamer4yu
18th February 2010, 06:46
I created a QGraphicsView and added a QGraphicsScene that contained the control widgets.
You could have simply made the control widgets as child widgets of the graphics view, if the control widgets are not some graphics items.
And if the control widgets are graphics items, then theres QGraphicsItem::ItemIgnoresTransformations flag in QGraphicsItem

johnsoga
18th February 2010, 14:29
You could have simply made the control widgets as child widgets of the graphics view

I need to rotate the widgets based on which side of the table they are on, that is why I need to have them in a graphics scene


theres QGraphicsItem::ItemIgnoresTransformations flag in QGraphicsItem

This is exactly what I was look for, I will see if it works the way I expect.

johnsoga
18th February 2010, 15:25
I set the flag QGraphicsItem::ItemIgnoresTransformations and that keeps the widget from scaling when I scale the view but when I pan around the widget doesn't stay in view. If i set the widget's parent to the view then I can't rotate the widget. How can I keep the widget that I add to a scene from scaling and moving with the scene? Following is the code I am using to add the widget to the scene, I added a very large pixmap to the scene first so this is after that:



QPushButton *button = new QPushButton( "Hello World" );
button->move( 300, 300 );
button->setFixedSize( 200, 200 );
QGraphicsProxyWidget *proxy = view.scene()->addWidget( button );
proxy->setFlag( QGraphicsItem::ItemIgnoresTransformations, true );
proxy->rotate( 180 );


Thanks,
Gabe