マウスがQTextEdit上にないときにマウスホイールを回すと、そのような場合にスクロールバーは移動しませんが、それでもマウスホイールでスクロールバーを移動したいので、どうすればこの機能を実装できますか? Microsoft Word などの一部のソフトウェアにこの機能があることは知っています。
この機能を以下のように実装したのですが、マウスホイールでスクロールバーを上または下に移動すると、エラーが発生しました: Python オブジェクトの呼び出し中に再帰の最大深度を超えました。誰でも助けることができますか?ここの私のコードhttp://codepad.org/1rq06qTk :
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_())