[PySide] capturing a simple "gesture" e.g. for scaling

Frank Rueter | OHUfx frank at ohufx.com
Sun Feb 14 08:51:18 CET 2016


So this kinda works, but I can't set the widget to be fully transparent 
without losing the mouseMoveEvent.
Any ideas?


from PySide import QtGui
from PySide import QtCore

class ModalScaleWidget(QtGui.QWidget):

     scaling = QtCore.Signal(float)

     def __init__(self, parent=None):
         super(ModalScaleWidget, self).__init__(parent)
         self.setWindowOpacity(0.1)
         self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
         self.setCursor(QtCore.Qt.SizeBDiagCursor)

     def mouseMoveEvent(self, event):
         '''Emit signal with the distance to the position of the first 
click'''
         point = event.pos() - self.posOnClick
         self.scaling.emit(point.manhattanLength())

     def mousePressEvent(self, event):
         '''Store the initial position when the user clicks'''
         self.posOnClick = event.pos()

     def mouseReleaseEvent(self, event):
         '''Close widget when mouse is released'''
         self.close()

     def keyPressEvent(self, event):
         '''Close widget when escape key is pressed'''
         if event.key() == QtCore.Qt.Key_Escape:
             self.close()

         super(ModalScaleWidget, self).keyPressEvent(event)

def test(distance):
     print distance

if __name__ == '__main__':
     import sys
     app = QtGui.QApplication(sys.argv)
     w = ModalScaleWidget()
     w.scaling.connect(test)
     w.showFullScreen()
     w.show()
     w.raise_()
     sys.exit(app.exec_())






On 14/02/16 6:39 pm, Frank Rueter | OHUfx wrote:
> Hi all,
>
> I am keen to figure out how I can create a mode that will output the 
> result of a simple gesture, such as a horizonal or vertical drag.
> This is not for phones/tablets, but rather for "invisible sliders", 
> where the user can press a hotkey to go into a certain "mode", then 
> click/drag to perform a certain action (such as scaling or drawing a 
> line on the screen).
>
> First I was thinking about an invisible widget that opens in full 
> screen and grabs the mouse event, but that seemed rather brute force 
> and ugly. Then I saw the docs for QGestureEvent but the examples I 
> found are sparse and all in C++. I'd be happy to explore those more 
> but I'm not sure if I'm even on the right track here.
>
> Can somebody point me in the right direction please?
>
> Cheers,
> frank
>
>
>
>
> -- 
> ohufxLogo 50x50 <http://www.ohufx.com> 	*vfx compositing 
> <http://ohufx.com/index.php/vfx-compositing> | *workflow customisation 
> and consulting <http://ohufx.com/index.php/vfx-customising>* *
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside

-- 
ohufxLogo 50x50 <http://www.ohufx.com> 	*vfx compositing 
<http://ohufx.com/index.php/vfx-compositing> | *workflow customisation 
and consulting <http://ohufx.com/index.php/vfx-customising>* *

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160214/9f7eadb4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160214/9f7eadb4/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ohufxLogo_50x50.png
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160214/9f7eadb4/attachment-0001.png>


More information about the PySide mailing list