1 year ago

#360208

test-img

Alex

Zooming qgraphicsview with mouse wheel and ctrl

I'm trying to implement zoom using a combination of Ctrl key and mouse wheel. But I came across the fact that when the cursor is inside QGraphicsView, the position of the scrollbar changes along with scaling. How to fix it? Here is the code I am using:

    class MyWin(QMainWindow, QGraphicsView):

        def __init__(self):  # constructor
            QtWidgets.QMainWindow.__init__(self)
        ...
        def wheelEvent(self, event):
            modifiers = QtWidgets.QApplication.keyboardModifiers()
            if modifiers == QtCore.Qt.ControlModifier:
               if event.angleDelta().y() > 0:
                   self.on_zoom_in()
               elif event.angleDelta().y() < 0:
                   self.on_zoom_out()

python

scroll

pyqt

pyqt5

scale

0 Answers

Your Answer

Accepted video resources