[Qt-qml] Qml extending with QGraphicsWidgets

bea.lam at nokia.com bea.lam at nokia.com
Wed Jul 14 02:24:46 CEST 2010


Hi Kate,

On 14/07/2010, at 2:29 AM, ext kate.alhola at nokia.com wrote:
[...]
> 
> I am implementing both paint() and boundingRect() as normal QGraphicsView code.
> 
> I also find dojo flipmo but it is also using proxywidget and not painting itself.
> 
> Is there some extra property that need to be set compared traditional c++  QGraphicsView items
> to get it displayed in Qml ? I tested that if I just add my widget to normal QGraphicsScene, it
> gets displayed and both paint() and boundingRect() get called.
>  

That sounds like it should work. If I make these changes to the Musician class in the tutorial, a red rectangle is painted:


class Musician : public QGraphicsWidget
{
    ...
public:
    ...
    void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
    {
        painter->fillRect(0, 0, 100, 100, QColor(Qt::red));
    }

    QRectF boundingRect () const
    {
        return QRectF(0, 0, 100, 100);
    }
};


The problem could be in the QML snippet:

>>> 
>>> Qml fragment creating widget is
>>> ¨Rectangle {
>>>         x:200
>>>         y:20
>>>         border.width:1
>>>         border.color:"black"
>>>         width: 60; height: 100
>>>       GaugeBand {
>>>         anchors.fill: parent
>>>         name: "MiuMau"
>>>         }
>>>     }


If the Rectangle is the root component, its x value of 200 is pushing it outside of the window, which means its child (the GaugeBand) is never painted.


regards,

Bea






More information about the Qt-qml mailing list