'How to make scrollbarscroll during MouseMoveEvent?
There is no scrollbar set aside from the view's default. Image that is displayed is large therefore scorllbar appears. I want scrolling to happen whenever position changes. Say when mousePressed an object called lastposition(x,y) is stored. If mouse is moved, lastposition(x,y) will be changed, therefore scrolling should appear. The code so far is:
class MainWindow(self, MainWindow):
self.scene = QGraphicsScene()
self.view = MyGraphicsView(self.scene, parent=self)
self.view.rubberBandRectGiven.connect(self.cropEnd)
self.view.horizontalScrollBar().valueChanged.connect(self.sceneMoved)
self.view.verticalScrollBar().valueChanged.connect(self.sceneMoved)
def sceneMoved(self):
sceneRect = self.view.mapToScene(self.view.rect()).boundingRect()
self.chooseImage(east, north, int(abs(sceneRect.x())), int(abs(sceneRect.y())), sceneRect.width(), sceneRect.height())
self.resizeScene()
if self.hasGrid:
self.drawGrid()
class MyGraphicsView(QGraphicsView):
rubberBandRectGiven = pyqtSignal(QRect)
def __init__(self, scene, parent=None):
super().__init__(scene, parent)
self.main = parent
self.setMouseTracking(True)
self.pos1 = QPoint()
self.rubberBand = QRubberBand(QRubberBand.Rectangle, self)
self.rubberBand.hide()
self.rubberBandActive = False
return
def mousePressedEvent(self, event):
.....
posScene = self.mapToScene(event.pos())
(self.lastPositionx, self.lastPositiony) = (int(posScene.x()), int(posScene.y()))
......
def mouseMoveEvent(self, event):
p = self.parent()` #MainWindow
posScene = self.mapToScene(event.pos())
(x, y) = (int(posScene.x()), int(posScene.y()))
if (self.lastPositionx-x ==0) and (self.lastPositiony-y!=0):
p.view.verticalScrollBar().setValue(100)
if (self.lastPositionx-x !=0) and (self.lastPositiony-y==0):
p.view.horizontalScrollBar().setValue(100)
if (self.lastPositionx-x !=0) and (self.lastPositiony-y!=0):
p.view.horizontalScrollBar().setValue(100)
p.view.verticalScrollBar().setValue(100)
But it doesn't scroll. Is there a way to make scrolling to happen?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
