سؤال

I have a QGraphicsView on a widget which im adding a number of items to.

some of these are polygons and some are ellipses (Both QGraphicsItems) when i zoom the Graphics view

void Test::on_verticalSlider_sliderMoved(int position)
{
    ui->graphicsView->scale(1.1,1.1);
}

the ellipses just get bigger and bigger but i want them to shrink so that they basically stay the same shape no matter how far zoomed in i am, so basically i want the polygons to be zoomed in on but not the points i have plotted onto these polygons...if that makes sense

dont know it makes it easier but all of the ellipse points plotted at any one time are within the same QGraphicsItemGroup so there could be a flag i can set on the entire group to do this?

anyway i would be greatful for any help with this

thanks

EDIT ------ CODE SAMPLE

item is the QGraphicsEllipseItem, and m_group_point is a QGraphicsItemGroup

 item->setParentItem(m_group_point.get());

then i add the group to a scene

m_scene2->addItem(m_group_point.get());

then add that scene to the view

ui->graphicsView->setScene(m_scene2.get());

they are .get because they are shared pointers

هل كانت مفيدة؟

المحلول

well, ignoreTransformation indeed a proper way to go.

QGraphicsItem::ItemIgnoresTransformations: The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately. You must call deviceTransform() to map coordinates and detect collisions in the view. By default, this flag is disabled. This flag was introduced in Qt 4.3.

About stay in the middle, you should move ellipses within scene to proper position, so they have proper scene coordinates, and then you instruct to ignore transformation of the view, so they will ignore any zooming/rotation/etc as mentioned in documentation.

نصائح أخرى

The Qt docs states this about the flag QGraphicsItem::ItemIgnoresTransformations: -

The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored).

Which is what you want. You've added your items to a QGraphcisItemGroup. For this, Qt help states: -

QGraphicsItemGroup ignores the ItemIgnoresTransformations flag on its children (i.e., with respect to the geometry of the group item, the children are treated as if they were transformable).

Reading into this, the QGraphicsItem uses the ItemIgnoreTransformations flag based on its parent, which in your case is the QGraphicsGroup, but this class ignores the flag on its children, which is likely to be causing the issue you're seeing.

Therefore, do not set the flag on the parent group, but on its children.

Try setting the ItemIgnoresTransformations flag on the objects that you want to keep constant-sized.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top