PDA

View Full Version : larger(not to scale) a exist QPixmap and paint more thing on the blank space



calmspeaker
8th July 2011, 06:57
QPixmap.transformed(QTransform::fromTranslate(x,y) ) did not have a good result.
Is there a way?

ChrisW67
8th July 2011, 07:37
Have you tried QPixmap::scaled(), QPixmap::scaledToWidth() and QPixmap::scaledToHeight() ?

Where do you want to put the larger QPixmap? On a QLabel? Then just have a look at QLabel::scaledContents()

calmspeaker
8th July 2011, 08:19
yes,i tried the scaled(), but it did not work as I wanted. It just scaled the whole picture. what i wanted is just larger the paint area and leave the origin picture unchanged.Then I will draw something on the blank area.

Added after 32 minutes:

Is it a complicated problem?

meazza
8th July 2011, 08:29
Well if you just want to adjust the size of the paint area it is not very complicated. Lets say that you are painting in a QWidget then in paintEvent() you can do something like this.


QPixmap example;
example.load("Picturepath");
QSize pixmapSize = example.size();
this->resize(pixmapSize);

Edit: And of course use QPainter::drawPixmap after that

MrShahi
8th July 2011, 08:32
Use QPainter inside paint event and draw pixmap through
void QPainter::drawPixmap ( int x, int y, int width, int height, const QPixmap & pixmap )
I hope it will help you...

calmspeaker
8th July 2011, 09:06
You did help me! Thank you.

QPixmap pixicon = item->icon(column).pixmap(QSize(32,32));//the origin icon
QPixmap pix(32,32);//store the modified icon
pix.fill(Qt::transparent);
QPainter paint(&pix);
paint.drawPixmap(16,16,16,16,pixicon);//bottom right paint pixicon

paint.drawLine(QPointF(12,0),QPointF(12,24));//modify the pixmap
paint.drawLine(QPointF(0,12),QPointF(24,12));