View Full Version : QPicture Clip
whitefurrows
17th July 2006, 13:52
Hi,
i try to clip a QPicture:
QPicture pic;
QPicture target;
pic.load("c:/pic.png");
if ( !pic.isNull ( ) )
{
QRect cut ( 0, pic.height()-250 ,250,250);
QPainter painter ( &target );
painter.setClipRect(cut);
painter.drawPicture(0, 0, pic);
painter.end();
}
target.save("c:/picClip.png");
This Code don't work, why?
Thank's in advance
Whitefurrows
jacek
17th July 2006, 14:16
This Code don't work, why?
What exactly doesn't work? And shouldn't you use QPixmap instead of QPicture?
whitefurrows
19th July 2006, 22:47
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:
void Report::printButton_clicked( const QString& html )
{
QTextDocument doc;
QAbstractTextDocumentLayout::PaintContext ctx;
float w=533; // page width
float h=754; // page height
doc.setHtml(html);
// Set the TextDocument's page size
doc.setPageSize( QSizeF(w, h) );
//int pageCount=doc.pageCount();
QAbstractTextDocumentLayout *docLayout = doc.documentLayout();
QPainter p;
//for ( int page=1; page<=pageCount; page++){
QPicture pic;
p.begin(&pic); // Start painting
//QRectF view(0, (page - 1) * h, w, h);
//ctx.clip = view;
// page1 and page2 only for test, i wont use the loop
//Page1
ctx.clip = QRectF(0,0,w,h); // Set the context clip to the first page
layout->draw(&p,ctx);
//Page2
//ctx.clip = QRectF(0,h,w,h); // Set the context clip to the second page
//docLayout->draw(&p,ctx);
p.end(); // End painting
//picList.append(pic);
//}
}
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
whitefurrows
22nd July 2006, 00:11
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
jacek
22nd July 2006, 23:18
I've made a little test (see attachment) and it seems that QPainter::translate() is a key to success.
whitefurrows
23rd July 2006, 13:41
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.