Results 1 to 6 of 6

Thread: QPicture Clip

  1. #1
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QPicture Clip

    Hi,

    i try to clip a QPicture:

    Qt Code:
    1. QPicture pic;
    2. QPicture target;
    3.  
    4. pic.load("c:/pic.png");
    5.  
    6. if ( !pic.isNull ( ) )
    7. {
    8. QRect cut ( 0, pic.height()-250 ,250,250);
    9. QPainter painter ( &target );
    10. painter.setClipRect(cut);
    11. painter.drawPicture(0, 0, pic);
    12. painter.end();
    13. }
    14.  
    15. target.save("c:/picClip.png");
    To copy to clipboard, switch view to plain text mode 

    This Code don't work, why?

    Thank's in advance

    Whitefurrows

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPicture Clip

    Quote Originally Posted by whitefurrows
    This Code don't work, why?
    What exactly doesn't work? And shouldn't you use QPixmap instead of QPicture?

  3. The following user says thank you to jacek for this useful post:

    whitefurrows (19th July 2006)

  4. #3
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QPicture Clip

    Hi,

    i have many problems with clip a picture and i don’t know why. This Code is a simple Example to clip a Picture. What i try to do ist hat:

    Qt Code:
    1. void Report::printButton_clicked( const QString& html )
    2. {
    3. QAbstractTextDocumentLayout::PaintContext ctx;
    4.  
    5. float w=533; // page width
    6. float h=754; // page height
    7.  
    8. doc.setHtml(html);
    9. // Set the TextDocument's page size
    10. doc.setPageSize( QSizeF(w, h) );
    11. //int pageCount=doc.pageCount();
    12. QAbstractTextDocumentLayout *docLayout = doc.documentLayout();
    13.  
    14. //for ( int page=1; page<=pageCount; page++){
    15.  
    16. QPicture pic;
    17. p.begin(&pic); // Start painting
    18. //QRectF view(0, (page - 1) * h, w, h);
    19. //ctx.clip = view;
    20.  
    21. // page1 and page2 only for test, i wont use the loop
    22. //Page1
    23. ctx.clip = QRectF(0,0,w,h); // Set the context clip to the first page
    24.  
    25. layout->draw(&p,ctx);
    26.  
    27. //Page2
    28. //ctx.clip = QRectF(0,h,w,h); // Set the context clip to the second page
    29. //docLayout->draw(&p,ctx);
    30.  
    31. p.end(); // End painting
    32.  
    33. //picList.append(pic);
    34. //}
    35. }
    To copy to clipboard, switch view to plain text mode 

    The picture won't clip. Picture1 is OK but picture2 ist picture1 + picture2 and picture3 is picture1 + picture2 + picture3..... I think that is a QT-Bug (v4.1.0) or you know what is wrong?

    Greetings

    Whitefurrows
    Last edited by whitefurrows; 19th July 2006 at 22:57.

  5. #4
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: QPicture Clip

    I'm very sad, i have try a lot of hour to get it work. Please give me somebody a response. I'm greatful for everything!

    Thanks in advance

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPicture Clip

    I've made a little test (see attachment) and it seems that QPainter::translate() is a key to success.
    Attached Files Attached Files

  7. The following user says thank you to jacek for this useful post:

    whitefurrows (23rd July 2006)

  8. #6
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: QPicture Clip

    You are my hero! That's great, the code work perfect. It's unbelievable how easy to do. A lot of thanks to you for that splendid help.

    Best regards,

    Whitefurrows

Similar Threads

  1. Diff between QImage, QPixmap, QPicture
    By nupul in forum Newbie
    Replies: 6
    Last Post: 30th April 2008, 02:02
  2. QPicture does not play right
    By derick in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2006, 01:46

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.