PyQt5重写QDockwidget事件错误?

时间:2016-12-06 08:34:58

标签: events pyqt5 super qdockwidget

我有以下问题,我想自定义QDockwidget事件函数,调用super()已经给我一个错误,其中没有代码。 错误:

TypeError: invalid result from DockWindow.event(), an integer is required (got type NoneType)

这是我的实际代码:

from PyQt5.QtWidgets import QApplication, QDockWidget
from PyQt5.QtWidgets import QMainWindow
from PyQt5 import QtCore

import sys

class DockWindow(QDockWidget):
    def __init__(self, parent=None):
        super(DockWindow, self).__init__(parent, QtCore.Qt.Widget)

    def event(self, ev):
        # I actually want to do stuff here. But following already produces an error.
        super(DockWindow, self).event(ev)

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent, QtCore.Qt.Window)
        self.dock_window = DockWindow(parent=self)
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dock_window)

def main(argv):
    app = QApplication(sys.argv)

    win = MainWindow()
    win.show()

    app.exec_()

if __name__ == '__main__':
    main(sys.argv)

编辑:

return super(DockWindow, self).event(ev)  

诀窍!

0 个答案:

没有答案