[PyQt] Got error with QSplitterHandle
Gottfried Müller
gottfried.mueller at gmx.de
Sun Jul 14 08:31:31 BST 2019
Hi,
thanks also to Maurizio. Now it works fine. But there is a small
question again. Why is "createHandle" in MySplitter called two times?
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()
More information about the PyQt
mailing list