[PyQt] Got error with QSplitterHandle

Gottfried Müller gottfried.mueller at gmx.de
Sat Jul 13 09:05:46 BST 2019


I wanted to implement the qt example
https://doc.qt.io/qt-5/qsplitterhandle.html with PyQt5. And I've got an
error with my implementation:

TypeError: QSplitterHandle(Qt.Orientation, QSplitter): argument 1 has
unexpected type 'MySplitter'

Can anybody help? Here is the code of my implementation:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=missing-docstring

import sys

from PyQt5.QtWidgets import (
     QApplication, QWidget, QListView, QSplitter, QVBoxLayout,
QSplitterHandle
)
from PyQt5.QtCore import Qt


class MySplitterHandle(QSplitterHandle):

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

     def paintEvent(self, event):
         print("do something")


class MySplitter(QSplitter):

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

     def createHandle(self, orientation):
         return MySplitterHandle(orientation, self)


class ApplWindow(QWidget):

     def __init__(self, parent=None):
         super().__init__(parent)
         v01 = QListView(parent=self)
         v02 = QListView(parent=self)
         orientation = Qt.Vertical
         splitter = MySplitter(orientation, parent=self)
         splitter.createHandle(orientation)
         layout = QVBoxLayout()
         layout.addWidget(v01)
         layout.addWidget(splitter)
         layout.addWidget(v02)
         self.setLayout(layout)
         self.resize(400, 400)


def main():
     appl = QApplication(sys.argv)
     applWindow = ApplWindow()
     applWindow.show()
     return appl.exec_()


if __name__ == "__main__":
     main()



More information about the PyQt mailing list