View Full Version : Pixmap conversion
MrShahi
25th June 2008, 15:10
Hello Everyone........................
I wana convert a constant string into a pixmap .................
but I have no idea how will it happen????????
if anyone can help me ? I'll very thankful to him
Thanx:(
aamer4yu
25th June 2008, 18:25
I wana convert a constant string into a pixmap .................
Can you elaborate ?
Are you trying to save the contents of a textbox/textedit as pixmap ?? If yes, you may have a look at QWidget::render :)
mcosta
25th June 2008, 18:40
Use this
QPixmap myPix(100, 100);
QPainter painter;
painter.begin(&myPix);
painter.drawText(myPix.rect(), Qt::AlignHCenter | Qt::AlignVCenter, "Hello to All");
painter.end();
MrShahi
26th June 2008, 09:37
Thanx a lot mcosta........
I m very thankful to you...........you solved my problem
but again I need your help as u suggested I used that code in my program but problem is there how can we set the font size and font colour in that pixmap?????????
I m waiting your reply................:(
mcosta
26th June 2008, 10:21
Add the "// NEW LINE" section to previous posted code
QPixmap myPix(100, 100);
QPainter painter;
painter.begin(&myPix);
// NEW LINES: START
painter.setPen(Qt::yellow); // set Color to yellow
painter.setFont(QFont("Times", 16, QFont::Bold));
// NEW LINES: STOP
painter.drawText(myPix.rect(), Qt::AlignHCenter | Qt::AlignVCenter, "Hello to All");
painter.end();
MrShahi
26th June 2008, 10:48
thanx, you are really great ..............
you solved my problem......thanx aonce again...........
But mcosta ,there is again a little problem is arising....i.e the pixmap does not contain whole string and how the set the background colour of this pixmap..................???:(
mcosta
26th June 2008, 10:56
You can use QPainter::fillRect()
....
painter.fillRect(myPix.rect(), QBrush(myColor));
painter.drawText(....);
....
MrShahi
26th June 2008, 11:03
Thank you so much .......................
Now I have not any problem.................................:)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.