How to zoom in multiple objects?
-
I did something like this. I have a custom QGraphiscView, the important parts are:
@
class CoordinateSystem : public QGraphicsView{
....
public:
static double s_X_Scale;
static double s_Y_Scale;
signals:
void updatePartners(double factor);
protected:
void wheelEvent(QWheelEvent *event);
public slots:
void repaint();
void rescale(double factor);
private slots:
void setXScaleP();
void setYScaleP();
void setXScaleM();
void setYScaleM();
private:
QGraphicsScene *m_Scene;
...
}
@The slots and the repaint:
@void CoordinateSystem::rescale(double factor)
{
scale(factor, factor);
}void CoordinateSystem::setXScaleM()
{
s_X_Scale = 0.9;
s_Y_Scale = 1;
repaint();
}void CoordinateSystem::setYScaleM()
{
s_Y_Scale = 0.9;
s_X_Scale = 1;
repaint();
}void CoordinateSystem::setXScaleP()
{
s_X_Scale = 1.1;
s_Y_Scale = 1;
repaint();
}void CoordinateSystem::setYScaleP()
{
s_Y_Scale = 1.1;
s_X_Scale = 1;
repaint();
}void CoordinateSystem::repaint()
{
m_Scene->clear();
scale(s_X_Scale,s_Y_Scale);.....
}@When a mouse wheel event happens:
@void CoordinateSystem::wheelEvent(QWheelEvent *event)
{
double numDegrees = event->delta() / 8.0;
double numSteps = numDegrees / 15.0;
double factor = pow(1.125, numSteps);
scale(factor, factor);
updatePartners(factor);
}@And the connect:
@connect(coorsys1, SIGNAL(updatePartners(double)), coorsys2, SLOT(rescale(double)));@
So in my case, whenever a coordinate system is zoomed in / out (rescaled), every other coordinate system, which is connected to it will also be zoomed in / out (rescaled) by the same ammount.
Hope this could help you.
-
Could you put the objects you want to scale inside a kind of container and scale that? If I understand the way QML works correctly, that would make all the sub-objects contained in it scale proportionally too.
Is this the kind of scaling you are referring to, or am I misunderstanding?
-
Yes, it does scale everything inside, dealing with flickable's contentItem made me forget about that. That's where my problem is, Flickable zoom with dynamic children. I'm making some more tests here, I'll post more information then.
Thanks for the reminder!