Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DotWidget class qt5 support fix in function wheelEvent #22

Open
wants to merge 2 commits into
base: kinetic-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 additions & 14 deletions smach_viewer/src/smach_viewer/xdot/xdot_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@
import time
import re

from python_qt_binding import QT_BINDING_VERSION

#from PySide.QtCore import *
#from PySide.QtGui import *
try:
if QT_BINDING_VERSION.startswith('4'):
from PyQt4 import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
except:
elif QT_BINDING_VERSION.startswith('5'):
from PyQt5 import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from python_qt_binding.QtWidgets import QWidget, QMainWindow
else:
raise ValueError('Unsupported Qt version, supported versions: PyQt4, PyQt5')

#from python_qt_binding import *
#from python_qt_binding.QtCore import *
Expand Down Expand Up @@ -1347,6 +1351,12 @@ class DotWidget(QWidget):

def __init__(self, parent=None):
super(DotWidget, self).__init__(parent)

# qt version flag
self.qt4_version = False
if QT_BINDING_VERSION.startswith('4'):
self.qt4_version = True

self.graph = Graph()
self.openfilename = None

Expand Down Expand Up @@ -1639,10 +1649,7 @@ def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton and self.is_click(event):
x, y = event.x(), event.y()
url = self.get_url(x, y)
if url is not None:
self.emit(SIGNAL("clicked"), unicode(url.url), event)
else:
self.emit(SIGNAL("clicked"), 'none', event)
if url is None:
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)
Expand All @@ -1652,10 +1659,7 @@ def mouseReleaseEvent(self, event):
if event.button() == Qt.RightButton and self.is_click(event):
x, y = event.x(), event.y()
url = self.get_url(x, y)
if url is not None:
self.emit(SIGNAL("right_clicked"), unicode(url.url), event)
else:
self.emit(SIGNAL("right_clicked"), 'none', event)
if url is None:
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)
Expand All @@ -1668,11 +1672,21 @@ def on_area_scroll_event(self, area, event):
return False

def wheelEvent(self, event):
if event.delta() > 0:
self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT,
if self.qt4_version:
# PyQt4
if event.delta() > 0:
self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT,
pos=(event.x(), event.y()))
if event.delta() < 0:
self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT,
pos=(event.x(), event.y()))
else:
# PyQt5
if event.angleDelta().y() > 0:
self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT,
pos=(event.x(), event.y()))
if event.delta() < 0:
self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT,
if event.angleDelta().y() < 0:
self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT,
pos=(event.x(), event.y()))

def mouseMoveEvent(self, event):
Expand Down