0

我有一个paintEvent,每次我画一些东西时我都会添加背景,问题是我需要图像停止重复。

例如,如果我的背景图像是 20 像素 x 20 像素,而我的绘画区域是 40 像素 x 40 像素,那么背景是 4 个图像,我只需要一个。

这是我的代码。

1. QPainter painter; // painter for the canvas
2. painter.begin(this);
3. QPixmap backgroundImage;
4. backgroundImage.load("multimedia/monitor_image.png");
5. painter.fillRect(event->rect(), QBrush(backgroundImage));

谢谢您的帮助!

4

1 回答 1

1

有很多函数可以帮助缩放图片:

http://doc.qt.nokia.com/4.7-snapshot/qpixmap.html

如果您知道高度,请尝试“scaleToHeight”。

像这样的东西应该工作:

backgroundImage = backgroundImage.scaledToHeight(painter.height);

在调用 fillRect 之前执行此操作,如果它是一个完美的正方形,那么您应该没有问题。

于 2012-08-20T14:56:02.300 回答