[PyQt] Got error with QSplitterHandle

Barry barry at barrys-emacs.org
Sun Jul 14 08:43:12 BST 2019



> On 14 Jul 2019, at 08:31, Gottfried Müller <gottfried.mueller at gmx.de> wrote:
> 
> Hi,
> 
> thanks also to Maurizio. Now it works fine. But there is a small
> question again. Why  is "createHandle" in MySplitter called two times?

Once for each call to splitter.addWidget() maybe?

Barry

> 
> Gottfried
> 
> Here is my new 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.QtGui import QPainter
> from PyQt5.QtCore import Qt
> 
> 
> class MySplitterHandle(QSplitterHandle):
> 
>     def paintEvent(self, event):
>         print("start paintEvent")
>         painter = QPainter(self)
>         painter.fillRect(event.rect(), Qt.blue)
>         painter.end()
> 
> 
> class MySplitter(QSplitter):
> 
>     def createHandle(self):
>         print("creaMyHdl")
>         return MySplitterHandle(self.orientation(), self)
> 
> 
> class ApplWindow(QWidget):
> 
>     def __init__(self, parent=None):
>         super().__init__(parent)
>         v01 = QListView(parent=self)
>         v02 = QListView(parent=self)
>         #orientation = Qt.Vertical
>         orientation = Qt.Horizontal
>         splitter = MySplitter(orientation, parent=self)
>         splitter.addWidget(v01)
>         splitter.addWidget(v02)
>         layout = QVBoxLayout()
>         layout.addWidget(splitter)
>         self.setLayout(layout)
>         self.resize(400, 400)
> 
> 
> def main():
>     appl = QApplication(sys.argv)
>     applWindow = ApplWindow()
>     applWindow.show()
>     return appl.exec_()
> 
> 
> if __name__ == "__main__":
>     main()
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt



More information about the PyQt mailing list