Ich hab ein Dashboard auf Pyside6 kreiert, welches auf einem GUI von Wanderson basiert.
Leider hab ich zu spät bemerkt, dass Pyside6 auf einem Raspberry Pi garnicht unterstützt wird. Daher der wechsel auf PyQt5.
An dieser Stelle macht mir die Svg Verarbeitung aber Sorgen. Ich versuche dies hier einmal zu Beschreiben.
Das Modul aus dem Traceback:
Code: Alles auswählen
def icon_paint(self, qp, image, rect, color):
icon = QPixmap(image)
painter = QPainter(icon)
painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
painter.fillRect(icon.rect(), color)
qp.drawPixmap(
(rect.width() - icon.width()) / 2,
(rect.height() - icon.height()) / 2,
icon
)
painter.end()
Code: Alles auswählen
pi@raspberrypi:~/QT-AutoPi $ python3 main.py
QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout
QObject::connect: Cannot queue arguments of type 'QTextBlock'
(Make sure 'QTextBlock' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
Traceback (most recent call last):
File "/home/pi/QT-AutoPi/gui/widgets/py_left_menu/py_left_menu_button.py", line 188, in paintEvent
self.icon_paint(p, self._icon_path, rect_icon, self._set_icon_color)
File "/home/pi/QT-AutoPi/gui/widgets/py_left_menu/py_left_menu_button.py", line 239, in icon_paint
painter.fillRect(icon.rect(), color)
TypeError: arguments did not match any overloaded call:
fillRect(self, QRectF, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
fillRect(self, QRect, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'str'
fillRect(self, int, int, int, int, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
fillRect(self, QRectF, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
fillRect(self, QRect, Union[QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'str'
fillRect(self, int, int, int, int, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
fillRect(self, int, int, int, int, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
fillRect(self, QRect, Qt.GlobalColor): argument 2 has unexpected type 'str'
fillRect(self, QRectF, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
fillRect(self, int, int, int, int, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
fillRect(self, QRect, Qt.BrushStyle): argument 2 has unexpected type 'str'
fillRect(self, QRectF, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
Dabei wird mir icon.rect doch der QRect abgerufen. Oder was missverstehe ich hier?
Das Icon Module sieht so aus:
Code: Alles auswählen
# ///////////////////////////////////////////////////////////////
#
# BY: WANDERSON M.PIMENTA
# PROJECT MADE WITH: Qt Designer and PySide6
# V: 1.0.0
#
# This project can be used freely for all uses, as long as they maintain the
# respective credits only in the Python scripts, any information in the visual
# interface (GUI) can be modified without any implication.
#
# There are limitations on Qt licenses if you want to use your products
# commercially, I recommend reading them on the official website:
# https://doc.qt.io/qtforpython/licenses.html
#
# ///////////////////////////////////////////////////////////////
# IMPORT QT CORE
# ///////////////////////////////////////////////////////////////
from qt_core import *
# PY ICON WITH CUSTOM COLORS
# ///////////////////////////////////////////////////////////////
class PyIcon(QWidget):
def __init__(
self,
icon_path,
icon_color
):
super().__init__()
# PROPERTIES
self._icon_path = icon_path
self._icon_color = icon_color
# SETUP UI
self.setup_ui()
def setup_ui(self):
# LAYOUT
self.layout = QVBoxLayout(self)
self.layout.setContentsMargins(0,0,0,0)
# LABEL
self.icon = QLabel()
self.icon.setAlignment(Qt.AlignCenter)
# PAINTER
self.set_icon(self._icon_path, self._icon_color)
# ADD TO LAYOUT
self.layout.addWidget(self.icon)
def set_icon(self, icon_path, icon_color = None):
# GET COLOR
color = ""
if icon_color != None:
color = icon_color
else:
color = self._icon_color
# PAINTER / PIXMAP
icon = QPixmap(icon_path)
painter = QPainter(icon)
painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
painter.fillRect(icon.rect(), color)
painter.end()
# SET PIXMAP
self.icon.setPixmap(icon)