Scaling I / O at a muscle point?

As seen in the figures. alt text

alt text

I have a QWidget inside a QScrollArea. A QWidget acts as a rendering widget for a cell image and some contour vector data. The user can scale to / from, and what just happens is to scale the QPainters and resize the QWidget accordingly.

Now I want to scale the I / O at a point under the mouse. (e.g. scaling in GIMP). How to calculate new scrollbar positions according to zoom level? Is it better to implement this with transforms without using scroll?

+3
source share
3 answers

One solution would be to output a new class from QScrollArea and re-execute wheelEvent , for example, to scale with the wheel mouse and at the current position of the mouse cursor.

This method works by adjusting the position of the scroll bar accordingly to reflect a new level of scaling. This means that while there is no visible scrollbar, scaling does not occur under the position of the mouse cursor. This is the behavior of most image viewer applications.

 void wheelEvent(QWheelEvent* e) { double OldScale = ... // Get old scale factor double NewScale = ... // Set new scale, use QWheelEvent... QPointF ScrollbarPos = QPointF(horizontalScrollBar()->value(), verticalScrollBar()->value()); QPointF DeltaToPos = e->posF() / OldScale - widget()->pos() / OldScale; QPointF Delta = DeltaToPos * NewScale - DeltaToPos * OldScale; widget()->resize(/* Resize according to new scale factor */); horizontalScrollBar()->setValue(ScrollbarPos.x() + Delta.x()); verticalScrollBar()->setValue(ScrollbarPos.y() + Delta.y()); } 
+3
source

Will void QScrollArea::ensureVisible(int x, int y, int xmargin = 50, int ymargin = 50) do what you need?

0
source

You need to pick up wheelEvent() in a QWidget, get event.pos () and pass it to QscrollArea.ensureVisible() , right after scaling your QWidget.

 def wheelEvent(self, event): self.setFixedSize(newWidth, newHeight) self.parent().ensureVisible(event.pos()) 

This should more or less produce what you want.

0
source

All Articles