How to zoom in multiple objects?



  • Hi, I've seen many example of scaling an image. Does anyone have some reference of zoom in/out multiple objects?

    Thanks



  • 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.



  • That's certainly a good start. I will work on that and then post a reply. Thanks



  • Wait, I have one question. I can't quite see what's happening. Does scale takes care of translating AND scaling? Because QML's Item scale doesn't do that.



  • Sorry, I've slipped over the QML tag, didn't know scale() is different. But there has to be a way to achieve the same behaviour (don't ask me how :) ).



  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.