qt - Qt5 / PyQt5 : Custom QML components with QML frontend and Python backend -
i want create qml module python "backend" if makes sense. basically, want use qml define how component looks, , implement specific behavior in python class, should extend qml-type , - in imagination - somehow must linkable qml component.
i understand how create custom class in python , making available qml via qmlregistertype. works far, drawing has implemented in class - no qml
(basically, want simliar way done in kivy kv-language)
a small example:
i implemented simple colorpicker widget this:
class colorwheel(qlabel): radius = 0 color_changed = pyqtsignal(float, float) def __init__(self, width, height): super().__init__() pixmap = qpixmap("colorwheel.png").scaled(width, height) self.setfixedsize(width, height) self.setpixmap(pixmap) self.radius = width / 2 def mousereleaseevent(self, event): # {...} mouse position, calc polar corrdinates (omitted) # emit signal: new color selected self.color_changed.emit(r, angle) def get_polar(self, x, y): # {...} calculate polar coordinates hsv color space (omitted) return r, theta
now want move gui-code (pixmap-drawing , on) qml file colorwheel.qml this:
import qtquick 2.0 item { image { id: img anchors.fill: parent source: "./colorwheel.png" } }
in main qml file main.qml want this:
import qtquick 2.2 import colorwheel 1.0 applicationwindow { title: qstr("test invoke") width: 500 height: 400 colorwheel { radius: 200 } }
is possible? not find in qt , pyqt documentation. it's making c++ classes available qml or other way around...
can point me in right direction?
many thanks!
if inherit qquickitem
, register - act item {}
.
if add properties on c++/python side - it'll item
properties.
colorwheelimpl.h
(make python equivalent):
class colorwheelimpl: public qquickitem { ... };
colorwheel.qml
:
import qtquick 2.0 colorwheelimpl { image { id: img anchors.fill: parent source: "./colorwheel.png" } }
Comments
Post a Comment