Results 1 to 3 of 3

Thread: Why QGraphicsItem moveing is valid in half?

  1. #1
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Why QGraphicsItem moveing is valid in half?

    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 :

    Qt Code:
    1. YPhoto::YPhoto(QPixmap&pix,QString&info,QGraphicsItem * parent)
    2. :QGraphicsItem(parent)
    3. {
    4. photo=new QGraphicsPixmapItem(this);
    5. photo->setPixmap(pix);
    6. baget=new QGraphicsTextItem(this);
    7. //name=new QGraphicsTextItem(this);
    8. //email=new QGraphicsTextItem(this);
    9.  
    10. QTextDocument* document=new QTextDocument(info);
    11. baget->setDocument(document);
    12. QRect rect=photo->pixmap().rect();
    13. baget->setTextWidth(rect.width());
    14. baget->setPos(this->pos().x(),this->pos().y()+rect.height());
    15.  
    16. }
    17.  
    18. QRectF YPhoto::boundingRect() const
    19. {
    20. QRect rect=photo->pixmap().rect();
    21. QFontMetrics fm(baget->font());
    22.  
    23. rect.setHeight(rect.height()+fm.height());
    24. return QRectF(rect);
    25. }
    26.  
    27. QPainterPath YPhoto::shape() const
    28. {
    29. QRect rect=photo->pixmap().rect();
    30. path.addRect(rect);
    31. path.addPath(baget->shape());
    32. return path;
    33. }
    34.  
    35. void YPhoto::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    36. {
    37. painter->drawPixmap(option->exposedRect,photo->pixmap(),option->exposedRect);
    38. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QGraphicsItem moveing is valid in half?

    You are doing it all wrong, so it seems. If you have a pixmap item as a child of your main item then you shouldn't try to draw its pixmap in the main item's painting routine - the child item will draw it. Your main item should just be a QGraphicsItemGroup containing two child items, no need to subclass anything even.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default

    thank you advice,this is very help,i will view document and try it again

    Thanks again, i use QGraphicsItemGroup,it worked fine
    Last edited by wysota; 13th December 2009 at 15:59.

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.