Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

My zoom doesn't work

2 posters

Go down  Message [Page 1 of 1]

1My zoom doesn't work Empty My zoom doesn't work Sun Jan 16, 2022 9:33 pm

feri



I'm trying to understand how the zoom works.
I did a simple test but the result is not what I was hoping for.
I search for an example component "rectangle-1" and then apply fit to view:

   Component* bordo = Circuit::self()->getComponent("Rectangle-1");
   fitInView(bordo, Qt::KeepAspectRatio);

I start from new0.png
My zoom doesn't work New010

I would like to get new1.png
My zoom doesn't work New113



but I get new2.png
My zoom doesn't work New210

Where am I wrong?
Greetings

2My zoom doesn't work Empty Re: My zoom doesn't work Sun Jan 16, 2022 10:53 pm

arcachofo

arcachofo

To see how zoom currently works have a look at CircuitView::wheelEvent().

You probably need to set the scale back to 1, then fitInView:

Code:

    Component* bordo = Circuit::self()->getComponent("Rectangle-1");

    resetMatrix();
    m_scale = 1;

    fitInView(bordo, Qt::KeepAspectRatio);

3My zoom doesn't work Empty Re: My zoom doesn't work Wed Jan 19, 2022 11:46 pm

feri



I did some tests and got some results with this code:

Code:

       fitInView(m_circuit->itemsBoundingRect(), Qt::KeepAspectRatio);
       scale( 0.27061, 0.27061 );

I enlarge a rectangle that contains the components present in the window (as a dimension), not where the components are but the upper left vertex coincides with the upper left vertex of the window.
If the objects are in the upper left area it works, if they are in another area the view is empty in the upper left corner.
I would like the upper left corner of the window to coincide with the upper left corner of the rectangle returned by itemsBoundingRect () as fi can do.
Greetings

4My zoom doesn't work Empty Re: My zoom doesn't work Thu Jan 20, 2022 12:04 am

arcachofo

arcachofo

I think m_circuit->itemsBoundingRect() returns a rectangle in QGraphicsScene coordinates, that is: relative to circuit canvas.
You probably need to map that rectangle to QGraphicsView coordinates.
Have a look at: https://doc.qt.io/qt-5/qgraphicsview.html#mapFromScene

5My zoom doesn't work Empty Re: My zoom doesn't work Tue Jan 25, 2022 10:07 pm

feri



Subcircuits give me an itemsBoundingRect ()
much larger than necessary see image:

My zoom doesn't work Subcir10

it is possible to avoid it.
Greetings

6My zoom doesn't work Empty Re: My zoom doesn't work Wed Jan 26, 2022 12:25 am

arcachofo

arcachofo

To see what is causing the problem in that subcircuit, can you do this? :

Comment out line 292 at src/gui/circuitwidget/subcircuit.cpp :
//comp->setHidden( true, true );

Then take an screenshot with that subcircuit in the scene.

7My zoom doesn't work Empty Re: My zoom doesn't work Wed Jan 26, 2022 10:32 pm

feri



I was doing tests on version 0.4.15.
Version 1.0.0 does not have this problem.
I have eliminated the problem from 0.4.15 by copying from 1.0.0.
I have implemented a slot that performs a simple zoom all
also works on version 1.0.0, there will definitely be a
better way but I have not found examples on the net.

Code:

circuitview.cpp

QAction* ZoomAllAction = menu.addAction( QIcon( ":/zoomall.png"),tr("ZoomAll") );
        connect( ZoomAllAction, SIGNAL( triggered()), this, SLOT(slotZoomAll()) );


void CircuitView::slotZoomAll()
{
      resetTransform();
      m_circuit->update();
      updateSceneRect(sceneRect());
      QRectF rectframe = frameRect();
      qreal a_ratio = rectframe.width() / rectframe.height();
      QRectF rectitem = m_circuit->itemsBoundingRect();
      QPointF p0 = rectitem.topLeft();
      qreal rectitem_H = rectitem.height();
      qreal rectitem_W = rectitem.width();
      if (rectitem_W / rectitem_H > a_ratio) {
          rectitem_H = rectitem_W / a_ratio;
      }
      else {
          rectitem_W = rectitem_H * a_ratio;
      }
      qreal val = (3200 / rectframe.width() + 2400 / rectframe.height()) / 2.0;
      QRectF rectall = QRectF(p0.x(), p0.y(), rectitem_W * val, rectitem_H * val);
      if (!rectitem.isEmpty()) {
          fitInView(rectall, Qt::KeepAspectRatio);
          m_circuit->setSceneRect(m_circuit->itemsBoundingRect());
      }
      else {
          m_circuit->setSceneRect(QRect(-1600, -1200, 3200, 2400));
          scale(0.27, 0.27);
      }
}
Greetings

8My zoom doesn't work Empty Re: My zoom doesn't work Thu Jan 27, 2022 10:34 am

arcachofo

arcachofo

The problem is that this breaks zoom and pan:
m_circuit->setSceneRect(m_circuit->itemsBoundingRect());

But I found the actual cause why fitInView() is not working.
I solved that issue and added Zoom to Fit at Rev 897.

Now this is working:
Code:
void CircuitView::slotZoomAll()
{
    QRectF r = m_circuit->itemsBoundingRect();
    fitInView( r, Qt::KeepAspectRatio );
}

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum