Hi,

currently Qml makes is very easy to use rectangles, but misses the other basic 
geometric shapes. As I understand, the main reason for not including them were 
possible performance issues, in particular during animation. A separate plugin 
though could easily come with the disclaimer that speed isn't guaranteed in 
all cases - so I started prototyping one that exposes the QPainter API to Qml.

Allowing imperative painting in a declarative world sounds counter-intuitive 
at first, but I feel easy access to ellipses, lines, polygons and other basic 
drawing functions can be very handy for prototyping. At the moment, you'd be 
required to dip back to C++ to do these things.

Example uses:

// logo impostor, should be fast since 'paint' is only evaluated once
// and cached in a pixmap
PaintArea {
    width: 100
    height: 100

    paint: {
        var p = beginRepaint();
        p.setPen({ color: "red" });
        p.drawEllipse(50, 50, 45, 45);
        p.drawText(10, 30, 100, 100, 0, "Impostor logo");
        return p;
    }
}

// basis for an Ellipse item, possibly slow since it repaints
// whenever width, height or penWidth change
PaintArea {
    property real penWidth: 3

    paint: {
        var p = beginRepaint();
        p.setPen({ width: penWidth });
        p.drawEllipse(width/2, height/2, (width-penWidth)/2, (height-
penWidth)/2);
        return p;
    }
}

The code for this prototype is available at 
http://gitorious.org/qml-painterplugin . It's functional, but incomplete and 
mainly intended to illustrate the idea.

Could something like this eventually become part of Qt's standard Qml plugins? 
(Qt.labs.painter?)

Cheers,
Christian
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to