Hi,
I have problems getting mouse events on my custom implemented pixmap item and text item. I am implementing boundingRect function in following way, can you please suggest what am I doing wrong? It seems that I am making some obvious mistake but not able to catch it :-(
QRectF ITGraphicsPixmapItem
::boundingRect() const {
qreal penWidth = 1;
QRectF rect
= QRectF(0-penWidth
/2,
0-penWidth
/2,itemSize.
width()+penWidth,itemSize.
height()+penWidth
);
if(itemIsSelected)
rect.adjust(-m_CornerSize,-m_CornerSize,m_CornerSize,m_CornerSize);
return rect;
}
QRectF ITGraphicsPixmapItem::boundingRect() const
{
qreal penWidth = 1;
QRectF rect = QRectF(0-penWidth/2,0-penWidth/2,itemSize.width()+penWidth,itemSize.height()+penWidth);
if(itemIsSelected)
rect.adjust(-m_CornerSize,-m_CornerSize,m_CornerSize,m_CornerSize);
return rect;
}
To copy to clipboard, switch view to plain text mode
This way I get hover even only if the mouse cursor in somewhere boundary like (0,0,itemSize.width()+m_CormerSize,itemSize.height ()+m_CornerSize). It seems to be some problem with negative x and y coordinates. What is the correct way to implement this then?
QRectF ITGraphicsTextItem
::boundingRect() const {
qreal penWidth = 1;
if(itemIsSelected)
rect.adjust(-m_CornerSize,-m_CornerSize,m_CornerSize,m_CornerSize);
return rect;
}
QRectF ITGraphicsTextItem::boundingRect() const
{
qreal penWidth = 1;
QRectF rect = QGraphicsTextItem::boundingRect();
if(itemIsSelected)
rect.adjust(-m_CornerSize,-m_CornerSize,m_CornerSize,m_CornerSize);
return rect;
}
To copy to clipboard, switch view to plain text mode
This way I get hover event only if the mouse cursor in QGraphicsTextItem::boundingRect(). While painting, I can easily use bounding Rect with intended results but mouse events don't work on updated bounding rect. Can you please help me, Why is it doing so?
Regards,
Manoj
Bookmarks