Hello everyone
i subclass QGraphicsItem, in constractor,i add QGraphicsPixmapItem,and a
QGraphicsTextItem. When drag this item
Why drag is an effective second half, while the upper part of the void?
this is my code :
{
photo->setPixmap(pix);
//name=new QGraphicsTextItem(this);
//email=new QGraphicsTextItem(this);
baget->setDocument(document);
QRect rect
=photo
->pixmap
().
rect();
baget->setTextWidth(rect.width());
baget->setPos(this->pos().x(),this->pos().y()+rect.height());
}
QRectF YPhoto
::boundingRect() const {
QRect rect
=photo
->pixmap
().
rect();
rect.setHeight(rect.height()+fm.height());
}
{
QRect rect
=photo
->pixmap
().
rect();
path.addRect(rect);
path.addPath(baget->shape());
return path;
}
{
painter->drawPixmap(option->exposedRect,photo->pixmap(),option->exposedRect);
}
YPhoto::YPhoto(QPixmap&pix,QString&info,QGraphicsItem * parent)
:QGraphicsItem(parent)
{
photo=new QGraphicsPixmapItem(this);
photo->setPixmap(pix);
baget=new QGraphicsTextItem(this);
//name=new QGraphicsTextItem(this);
//email=new QGraphicsTextItem(this);
QTextDocument* document=new QTextDocument(info);
baget->setDocument(document);
QRect rect=photo->pixmap().rect();
baget->setTextWidth(rect.width());
baget->setPos(this->pos().x(),this->pos().y()+rect.height());
}
QRectF YPhoto::boundingRect() const
{
QRect rect=photo->pixmap().rect();
QFontMetrics fm(baget->font());
rect.setHeight(rect.height()+fm.height());
return QRectF(rect);
}
QPainterPath YPhoto::shape() const
{
QPainterPath path;
QRect rect=photo->pixmap().rect();
path.addRect(rect);
path.addPath(baget->shape());
return path;
}
void YPhoto::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawPixmap(option->exposedRect,photo->pixmap(),option->exposedRect);
}
To copy to clipboard, switch view to plain text mode
Bookmarks