---
title: "QPainter在4K屏上绘制不清楚 (QPainter not clear in high DPI)"
author: "johnsmith9th"
date: "2021-12-31T10:23:57Z"
tags: []
categories: ["编程语言"]
slug: "qpainter-4k-qpainter-not-clear-in-high-dpi"
draft: false
lastmod: "2021-12-31T10:27:53Z"
id: 2524072
url: "https://johnsmith9th.iteye.com/blog/2524072"
---

如果是先将内容绘制到一个图片缓存上的话，这个图片缓存需要放大到设备坐标系了，而不是简单的逻辑坐标系大小。参考来源： https://stackoverflow.com/questions/42011410/qt-drawing-high-dpi-qpixmaps。

具体做法如下：

假如代码是这么写的： m\_pBufferImg = new QPixmap(this-&gt;width(),this-&gt;height());QPainter p(\*m\_pBufferImg);...

则需要改为： qreal dpr = this-&gt;devicePixelRatioF();m\_pBufferImg = new QPixmap(this-&gt;width()\*dpr,this-&gt;height()\*dpr); m\_pBufferImg r-&gt;setDevicePixelRatio(dpr); QPainter p(\*m\_pBufferImg);...