setRenderHint设置反走样

    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    painter.setPen(QPen(Qt::black, 3, Qt::DashDotLine, Qt::RoundCap));
    painter.setBrush(QBrush(Qt::green, Qt::Dense1Pattern));
    painter.drawEllipse(50, 200, 150, 80);

在绘制图形时,会出现锯齿的走样图形,Qt内置了反走样算法,默认是关闭的,需要显性的打开。

使用setRenderHint函数可以启动反走样,告诉QPainter用不同的颜色强度绘制边框以减少视觉扭曲,这种扭曲一般在边框转换为像素的时候发生。由此生成的结果是可以在支持这一特性的平台和设备上得到平滑的边缘。

反走样的效果要比走样的好得多。但是反走样是一种比较复杂的算法,在一些对图像质量要求不高的应用中,是不需要进行开启反走样的。

为了提高效率,一般的图形绘制,都是默认不开启反走样的。

QPainter::Antialiasing0x01Indicates that the engine should antialias edges of primitives if possible.
QPainter::TextAntialiasing0x02Indicates that the engine should antialias text if possible. To forcibly disable antialiasing for text, do not use this hint. Instead, set QFont::NoAntialias on your font's style strategy.
QPainter::SmoothPixmapTransform0x04Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.
QPainter::HighQualityAntialiasing0x08This value is obsolete and will be ignored, use the Antialiasing render hint instead.
QPainter::NonCosmeticDefaultPen0x10This value is obsolete, the default for QPen is now non-cosmetic.
QPainter::Qt4CompatiblePainting0x20Compatibility hint telling the engine to use the same X11 based fill rules as in Qt 4, where aliased rendering is offset by slightly less than half a pixel. Also will treat default constructed pens as cosmetic. Potentially useful when porting a Qt 4 application to Qt 5.
QPainter::LosslessImageRendering0x40Use a lossless image rendering, whenever possible. Currently, this hint is only used when QPainter is employed to output a PDF file through QPrinter or QPdfWriter, where drawImage()/drawPixmap() calls will encode images using a lossless compression algorithm instead of lossy JPEG compression. This value was added in Qt 5.13.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值