I have a main window designed in QT Designer. Among other things it has a scroll area with a label used to display image. I want to replace default mouse wheel handler which scrolls image with my own that zooms image instead. If I add wheelEvent event to my class that inherits the main window class from compiled qt designer file (Ui_MainWindow) it zooms image no matter where the mouse pointer is and which widget is active. Even more the scroll area keeps handling wheel event before processing my own handler that does zooming. I'm not quite sure how do I replace standard wheelevent event handler so that zooming works only when scrollarea is active? I know how to do that If I was coding GUI myself, but with QT Designer I'm not supposed to touch the compiled version of GUI. Below is the piece of code that handles zooming. It won't work without QT Designer compiled code though...
from MainWindow import Ui_MainWindow
if __name__ == "__main__":
class CCDInspectorMainWindow(QMainWindow, Ui_MainWindow):
ImageWidth=0
ImageHeight=0
zoom=1.0
def __init__(self, parent = None):
super(CCDInspectorMainWindow, self).__init__(parent)
self.setupUi(self)
QObject.connect(self.actionOpen_File, SIGNAL("triggered()"), self.openDialog)
self.imageMap=QImage(0,0,QImage.Format_RGB888)
def openDialog(self):
fileObj=QFileDialog.getOpenFileName(self,"Open image", filter="All Image Files (*.png *.xpm *.jpg *.tif *.fit *.fits *.cr*)")
self.imageMap=QImage(fileObj)
self.ImageWidth=self.imageMap.width()
self.ImageHeight=self.imageMap.height()
self.updateImages()
def wheelEvent(self,event):
self.zoom = self.zoom+event.delta() / 1200.0
if self.zoom<0:
self.zoom=0
self.updateImages()
def updateImages(self):
self.setOriginalImage()
self.setSplitImage()
def setOriginalImage(self):
self.OriginalImage.setPixmap(QPixmap.fromImage(self.imageMap.scaled(int(self.ImageWidth*self.zoom),int(self.ImageHeight*self.zoom),aspectRatioMode=Qt.IgnoreAspectRatio, transformMode=Qt.FastTransformation)))