[Qt-interest] adding another item in QGraphicsItem

Sean Harmer sean.harmer at maps-technology.com
Sat Apr 25 10:29:42 CEST 2009


On Saturday 25 April 2009 07:47:44 chandrasekar wagmare wrote:
> hi friends,
>           i am designing a QGraphicsView having several customized
> QGraphicsRectItem ...
>
>    one of the customized item is ProgressItem
>
>
> ProgressItem::ProgressItem(const QRectF &rect)
>
>             : QGraphicsRectItem(rect)
>
> i will construct it in QGraphicsScene with QRectF(0, 0, 80, 40)
>
> my doubt is ..." how can i insert a QGraphicsTextItem inside the
> QGraphicsRectItem ...
>
> previously i use  :paint(QPainter *painter, const  QStyleOptionGraphicsItem
> *o, QWidget *widget)
>              and use painter->addText();
>
> but i dont know how to introduce an new item (QGraphicsTextItem) inside the
> rectItem() ...
>
>      can anybody please help me .....
Erm, have you simply tried constructing a QGraphicsTextItem in the constructor 
of your ProgressItem object? Just pass "this" as the parent and position it in 
your objects local coordinate system and all should be good.

ProgressItem::ProgressItem(const QRectF &rect)
 : QGraphicsRectItem( rect )
{
	m_textItem = new QGraphicsTextItem( this );
	// Calculate reasoable x and y coords here...
	m_textItem->setPos( QPointF( x, y ) );
}

Sean



More information about the Qt-interest-old mailing list