gpt4 book ai didi

c++ - 如何在 Qt 中用图像填充 Rectangle(Rect 对象)?

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:58 25 4
gpt4 key购买 nike

我已经试过了:

QBrush brush(QPixmap(":/new/prefix1/car.jpg"));
painter.setBrush(brush);
QRectF car(positions[i],120, 20, 10 );
painter.drawRect(car);

它显示了图像,但在 QPaint 中的模拟过程中会重复出现。我想要一种用图像填充矩形的方法,但我没有找到 Rect 的任何特定方法。有什么技巧吗?

最佳答案

使用 QPainters drawPixmap。有一个重载函数,它需要一个 QPixmap 和一个 QRect,像素图将被绘制到其中:

http://doc.qt.io/qt-5/qpainter.html#drawPixmap-9

关于c++ - 如何在 Qt 中用图像填充 Rectangle(Rect 对象)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com