PDA

View Full Version : QGraphicsItem: ignore scaling without ignoring rotations



Lodorot
19th June 2009, 09:32
Hi,

I've got a QGraphicsView which allows translations, rotations and scaling and there are some QGraphicsItem I want to ignore the scaling.

If I set QGraphicsItem::ItemIgnoresTransformations all rotation, zoom or shear transformations are ignored. Is there a way to keep the size of a QGraphicsItem fixed without ignoring all transformations.

Does the QGraphicsItem gets informed when the QGraphicsView calls scale, so that I can react on the scaling and scale the QGraphicsItem back.

Thank you in advance

Markus

PS: I'm using Qt 4.5.1.

shentian
19th June 2009, 11:38
I would keep a list of all items that you don't want to scale, and then do this for scaling:



QList<QGraphicsItem*> nonScalingItems;
QGraphicsView* view;

// ...

view->scale(scaleX, scaleY);
foreach (QGraphicsItem* item, nonScalingItems)
{
item->scale(1.0/scaleX, 1.0/scaleY);
}

BinbinDesbois
25th March 2011, 10:18
Hi

What I've done to solve this problem
Note: myGraphicsView->initialScale is != to 1.f in my application but for most of code, you can replaced it by 1;


MyItem::MyItem(QGraphicsView* _myGraphicsView )
{
myGraphicsView = _myGraphicsView;
connect(myGraphicsView ,SIGNAL(scaleChanged(float)),this,SLOT(parentScale Changed(float)));
}

void MyItem::parentScaleChanged(float newScale)
{
setScale(myGraphicsView->initialScale/newScale);
}