Last active
February 24, 2020 09:39
-
-
Save Lesik/45ac04b5fb7355ed684bc3144ce860ad to your computer and use it in GitHub Desktop.
PyQt 5 pyqtProperty QSS example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from PyQt5.QtCore import QRect, pyqtProperty | |
from PyQt5.QtGui import QPaintEvent, QPainter, QColor, QPen | |
from PyQt5.QtWidgets import QWidget | |
from PyQt5.QtCore import Qt | |
class Widget(QWidget): | |
""" | |
https://www.riverbankcomputing.com/static/Docs/PyQt5/qt_properties.html | |
""" | |
def __init__(self): | |
super().__init__() | |
self.color = QColor("red") | |
self.setStyleSheet(""" | |
Square { | |
qproperty-textcolor: blue; | |
} | |
""") | |
@pyqtProperty('QColor') | |
def textcolor(self): | |
return self.color | |
@acolor.setter | |
def textcolor(self, value): | |
self.color = value | |
def paintEvent(self, event: QPaintEvent) -> None: | |
painter = QPainter(self) | |
pen = QPen() | |
pen.setColor(self.textcolor) | |
painter.setPen(pen) | |
rect = QRect(0, 0, painter.device().width(), painter.device().height()) | |
painter.drawRect(rect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment