[Qt-qml] Qml extending with QGraphicsWidgets

kate.alhola at nokia.com kate.alhola at nokia.com
Wed Jul 14 11:14:42 CEST 2010


On Jul 14, 2010, at 3:24 AM, Lam Bea (Nokia-MS-Qt/Brisbane) wrote:

> 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);
>    }
> };
> 

Thank you, that helped me, with one working reference i was able quickly to chase bug in to the corner and catch it.
The bug was actually in build and now my code works as intended.

Kate

> 
> 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