The item group did not seem to work for me, so I moved to a parent-child relationship. The rect item is the parent with the icon item being the child. I seem to have better control of the icon since its "coordinate system" is based on the parent. I was wondering if it is okay to call setPos in the paint method of the parent to control the position of the child.
void MyRectItem
::paint( QPainter *painter,
{
Q_UNUSED(widget);
Q_UNUSED(option);
qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
bool bShow = ( lod > 0.05 );
if( bShow )
{
painter->setPen( pen() );
painter->setBrush( brush() );
painter->drawRect( rect() );
}
if( bShow != m_bPainted && NULL != m_pIcon )
{
m_bPainted = bShow;
// this seems to work okay, but is it "legal" to make this setPos call?
m_pIcon
->setPos
( m_bPainted ? rect
().
topLeft() : QPointF( 0., 0.
) );
}
}
void MyRectItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget )
{
Q_UNUSED(widget);
Q_UNUSED(option);
qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
bool bShow = ( lod > 0.05 );
if( bShow )
{
painter->setPen( pen() );
painter->setBrush( brush() );
painter->drawRect( rect() );
}
if( bShow != m_bPainted && NULL != m_pIcon )
{
m_bPainted = bShow;
// this seems to work okay, but is it "legal" to make this setPos call?
m_pIcon->setPos( m_bPainted ? rect().topLeft() : QPointF( 0., 0. ) );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks