在 2013年7月19日星期五UTC+8下午2时25分55秒,Justin Israel写道:
> It depends on where the pointer currently is. If it is still within your app, 
> you could catch all wheel events and forward them to the line edit. But if 
> your mouse is outside of the app then another widget is free to grab the 
> focus away
> 
> 
> 
> 
> On Fri, Jul 19, 2013 at 6:05 PM, iMath <[email protected]> wrote:
> 
> when you turn the mouse wheel while the mouse is not on the QTextEdit ,the 
> scroll bars will not move in such case ,but I still want to move the scroll 
> bars by mouse wheel ,so how can I implement this function ?
> 
> I know some software like Microsoft Word have this feature
> 
> 
> 
> 
> 
> import sys
> 
> from PyQt4 import QtGui
> 
> class BoxLayout(QtGui.QWidget):
> 
>     def __init__(self, parent=None):
> 
>         QtGui.QWidget.__init__(self, parent)
> 
>         self.resize(100, 300)
> 
> 
> 
>         ok = QtGui.QPushButton("OK")
> 
>         cancel = QtGui.QPushButton("Cancel")
> 
> 
> 
>         vbox = QtGui.QVBoxLayout()
> 
>         vbox.addWidget(QtGui.QTextEdit("""This function returns true if the 
> contents of the MIME data object, specified by source , can be decoded and 
> inserted into the document. It is called for example when during a drag 
> operation the mouse enters this widget and it is necessary to determine 
> whether it is possible to accept the drag and drop operation.
> 
> 
> 
> 
> """))
> 
>         vbox.addWidget(ok)
> 
>         vbox.addWidget(cancel)
> 
> 
> 
>         self.setLayout(vbox)
> 
> 
> 
> app = QtGui.QApplication(sys.argv)
> 
> qb = BoxLayout()
> 
> qb.show()
> 
> sys.exit(app.exec_())
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Python Programming for Autodesk Maya" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> 
> To post to this group, send email to [email protected].
> 
> For more options, visit https://groups.google.com/groups/opt_out.

of course ,the precondition is that the  app still has focus 


I implement this feature like the following ,but when you move the scroll bars 
to the top or bottom by mouse wheel ,an error would occur : maximum recursion 
depth exceeded while calling a Python object.
anyone can help ?
code here :


import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class BoxLayout(QWidget):
    def __init__(self, parent=None):
        super(BoxLayout, self).__init__(parent)
        self.resize(100, 300)
       
        ok = QPushButton("OK")
        cancel = QPushButton("Cancel")
        self.textEdit = QTextEdit("""This function returns true if the contents 
of the MIME data object, specified by source , can be decoded and inserted into 
the document. It is called for example when during a drag operation the mouse 
enters this widget and it is necessary to determine whether it is possible to 
accept the drag and drop operation.""")
        
        vbox = QVBoxLayout()
        vbox.addWidget(self.textEdit)
        vbox.addWidget(ok)
        vbox.addWidget(cancel)
        self.setLayout(vbox)
        
#        self.textEdit.installEventFilter(self)
#        
#    def eventFilter(self, obj, event):
#        if obj == self.textEdit:
#            if event.type() == QEvent.Wheel:
#                self.textEdit.wheelEvent(event)
#                return True
#            else:
#                return False
#        else:
#            return QMainWindow.eventFilter(self, obj, event)
#        
    
    def wheelEvent(self, event):
        self.textEdit.wheelEvent(event)

app = QApplication(sys.argv)
qb = BoxLayout()
qb.show()
sys.exit(app.exec_())

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to