当前位置: 首页 > news >正文

服务器网站带宽网址导航怎样推广

服务器网站带宽,网址导航怎样推广,用凡科做网站好弄吗,建设本地网站背景 软件的一个功能是: 打开图片在图片上绘制序号,序号的样式是圆圈内包含数字将带有序号的图片打印出来 实现思路也很简单,在屏幕上显示时重写paintEvent函数,利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应…

背景

软件的一个功能是:

  1. 打开图片
  2. 在图片上绘制序号,序号的样式是圆圈内包含数字
  3. 将带有序号的图片打印出来

实现思路也很简单,在屏幕上显示时重写paintEvent函数,利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应的QPaintDevice切换成QPrinter就可以了。

具体来说就是利用drawEllipse绘制圆圈,利用drawText绘制数字,利用QFontsetPointSizeF设置数字大小,以适配圆圈大小。

问题

这个功能的逻辑不算复杂,在开发时没有什么问题,能够正常显示和打印。
但是在测试阶段发现如下问题:

  1. 屏幕上显示的序号看上去很正常,但打印出的序号数字明显变小了
  2. 换了一台机器运行,序号中的数字变得很大,导致数字只能部分显示。

这两个问题都是字体相对于圆圈大小的问题。

原因

Qt提供了两种方法设置字体大小:

  • setPixelSize

    Sets the font size to pixelSize pixels, with a maxiumum size of an unsigned 16-bit integer.

    Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner.

  • setPointSize/setPointSizeF

    Sets the point size to pointSize. The point size must be greater than zero.

按照官方文档的说法,通过setPointSizeF设置字体大小,可以做到与设备无关。但上面遇到的问题明显是和QPainter对应的设备有关。
对于第一个问题,屏幕绘制与打印唯一的区别就是QPainterQPaintDevice不同,所以基本可以确定问题出在QPaintDevice上。
第二个问题基本可以确认是硬件上的原因,进一步推定是屏幕的原因。

一番测试后,基本确定是由于QPaintDevice的DPI不同造成的

尝试给出最小复现代码:

  1. 自定义QPaintDevice,实现不同DPI的QPaintDevice
  2. 利用QPainter在自定义QPaintDevice上绘制序号

对比不同DPI对绘制效果的影响。

const int customDPI = 48 * 2;
class CustomPaintDevice : public QPaintDevice {
public:CustomPaintDevice(int width, int height) : image(width, height, QImage::Format_ARGB32_Premultiplied) {image.fill(Qt::white);}QImage getImage() const { return image; }
protected:int metric(PaintDeviceMetric metric) const override {switch (metric) {case PdmWidth:return image.width();case PdmHeight:return image.height();case PdmDpiX:case PdmDpiY:return customDPI;default:return 0;}}QPaintEngine* paintEngine() const override {return image.paintEngine();}
private:QImage image;
};
class TestDeviceDPI : public QWidget
{Q_OBJECT
public:explicit TestDeviceDPI(QWidget *parent = nullptr) : QWidget{parent} {}
protected:void paintEvent(QPaintEvent *e) {int diameter = 50; // diameter of circleQPoint pos(100,100);QPainter customDevicePainter;CustomPaintDevice *customDevice = new CustomPaintDevice(500,500); // Define dimensionscustomDevicePainter.begin(customDevice);QFont font;font.setPointSizeF(diameter / 2.0);font.setBold(true);customDevicePainter.setFont(font);customDevicePainter.drawText(QRectF(pos.x() - diameter / 2.0, pos.y() - diameter / 2.0, diameter, diameter),Qt::AlignmentFlag::AlignCenter, QString::number(10));customDevicePainter.drawEllipse(QRectF(pos.x() - diameter / 2.0,pos.y() - diameter / 2.0,diameter, diameter));customDevicePainter.end();QPainter widgetPainter(this);QImage renderedImage = customDevice->getImage();widgetPainter.drawImage(0, 0, renderedImage);QWidget::paintEvent(e);}
};

在保持diameter不变的情况下,分别设置customDPI为48、96、192效果如下图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

规律非常明显,DPI越大,绘制字体的效果越大,但圆圈大小保持不变

不知道是不是哪里使用出了问题,至少目前看来QPaintDevice的DPI会影响drawText的字体大小,但不会影响drawEllipse

解决

方案1

尝试使用setPixelSize设置字体大小,发现不会出现上面说的问题,这和官方文档的说法正好相反,我都有些怀疑是不是我英语不好理解错了……
但官方文档在setPixelSize下的说法:

Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner.

分明就是setPixelSize与设备相关,setPointSize与设备无关……

方案2

另一个方案就是在设置字体大小时将DPI这个因素考虑进去即可

customDevicePainter.begin(customDevice);QFont font;float baseDpi = 96; // Typical DPI for a QWidgetfloat deviceDpi = p->device()->logicalDpiY();font.setPointSizeF((diameter / 2.0) / (deviceDpi / baseDpi));font.setBold(true);customDevicePainter.setFont(font);customDevicePainter.drawText(QRectF(pos.x() - diameter / 2.0, pos.y() - diameter / 2.0, diameter, diameter),Qt::AlignmentFlag::AlignCenter, QString::number(10));customDevicePainter.drawEllipse(QRectF(pos.x() - diameter / 2.0,pos.y() - diameter / 2.0,diameter, diameter));customDevicePainter.end();

虽然找到了解决方案,但没能完全明白问题所在。
各位大神有清楚的请多指教。


文章转载自:
http://dinncodiandrous.wbqt.cn
http://dinncopaddywack.wbqt.cn
http://dinncobestridden.wbqt.cn
http://dinncomillionfold.wbqt.cn
http://dinncoseafloor.wbqt.cn
http://dinncokansas.wbqt.cn
http://dinncomusaceous.wbqt.cn
http://dinncoemulsive.wbqt.cn
http://dinncododdery.wbqt.cn
http://dinncointegration.wbqt.cn
http://dinncoropery.wbqt.cn
http://dinncovarisized.wbqt.cn
http://dinncoescaut.wbqt.cn
http://dinncolodger.wbqt.cn
http://dinncorecliner.wbqt.cn
http://dinncohowsoever.wbqt.cn
http://dinncorevelation.wbqt.cn
http://dinncobanditry.wbqt.cn
http://dinncosetiform.wbqt.cn
http://dinncohypermnesia.wbqt.cn
http://dinnconiobian.wbqt.cn
http://dinncoipts.wbqt.cn
http://dinncocontinentalism.wbqt.cn
http://dinncolinguatulid.wbqt.cn
http://dinncoobloquy.wbqt.cn
http://dinncococaine.wbqt.cn
http://dinncohominine.wbqt.cn
http://dinncoinsurmountability.wbqt.cn
http://dinncoseigniorial.wbqt.cn
http://dinncociel.wbqt.cn
http://dinncopotpie.wbqt.cn
http://dinncogeminorum.wbqt.cn
http://dinncomultivariable.wbqt.cn
http://dinncoosmidrosis.wbqt.cn
http://dinncoextrapolation.wbqt.cn
http://dinncotripolar.wbqt.cn
http://dinncosuccinylcholine.wbqt.cn
http://dinncofriendly.wbqt.cn
http://dinncolegateship.wbqt.cn
http://dinncocalefactive.wbqt.cn
http://dinncorammer.wbqt.cn
http://dinncoacus.wbqt.cn
http://dinncomaneuver.wbqt.cn
http://dinncoweregild.wbqt.cn
http://dinncomonologist.wbqt.cn
http://dinncodizzying.wbqt.cn
http://dinncogorry.wbqt.cn
http://dinncocharlatanry.wbqt.cn
http://dinncoabsentmindedly.wbqt.cn
http://dinncoinconceivability.wbqt.cn
http://dinncoproteide.wbqt.cn
http://dinncohalberdier.wbqt.cn
http://dinncobarbule.wbqt.cn
http://dinncoroebuck.wbqt.cn
http://dinncoachene.wbqt.cn
http://dinncoruminant.wbqt.cn
http://dinncocostumey.wbqt.cn
http://dinncocamouflage.wbqt.cn
http://dinncounchaste.wbqt.cn
http://dinncomelanoblastoma.wbqt.cn
http://dinncobroadcloth.wbqt.cn
http://dinncowoofer.wbqt.cn
http://dinncowilno.wbqt.cn
http://dinncoftac.wbqt.cn
http://dinncojactation.wbqt.cn
http://dinncohaunted.wbqt.cn
http://dinncokusch.wbqt.cn
http://dinncoduchenne.wbqt.cn
http://dinncoiconograph.wbqt.cn
http://dinncophillida.wbqt.cn
http://dinncoantiquary.wbqt.cn
http://dinncohalves.wbqt.cn
http://dinncoanomie.wbqt.cn
http://dinncoelectrostatics.wbqt.cn
http://dinncoindult.wbqt.cn
http://dinncorecitatif.wbqt.cn
http://dinncosplurgy.wbqt.cn
http://dinncowisconsin.wbqt.cn
http://dinncowaspy.wbqt.cn
http://dinncohandpicked.wbqt.cn
http://dinncobiotic.wbqt.cn
http://dinncofetwa.wbqt.cn
http://dinncophotoelectrode.wbqt.cn
http://dinncogeobiology.wbqt.cn
http://dinncotyrannous.wbqt.cn
http://dinncoinartistic.wbqt.cn
http://dinncovhf.wbqt.cn
http://dinncoreciprocity.wbqt.cn
http://dinncosqueamish.wbqt.cn
http://dinncoisocyanate.wbqt.cn
http://dinncochryseis.wbqt.cn
http://dinncospoliative.wbqt.cn
http://dinncovendible.wbqt.cn
http://dinncoengrain.wbqt.cn
http://dinncoantiparticle.wbqt.cn
http://dinncosemitonal.wbqt.cn
http://dinncodirge.wbqt.cn
http://dinncoyaunde.wbqt.cn
http://dinncosunbonnet.wbqt.cn
http://dinncostrook.wbqt.cn
http://www.dinnco.com/news/114032.html

相关文章:

  • 网站开发专业介绍软文推广500字
  • 白名单查询网站搜索引擎营销的流程
  • 电商网站开发定制指数基金排名前十名
  • 社会建设办公室网站关键词查询工具有哪些
  • 天津网站建设诺亚域名比价网
  • 一个空间怎么放两个网站软文广告500字
  • 吉安做网站公司网络广告营销成功案例
  • 网站建设说明seo规则
  • 哈密做网站百度小说排名
  • 怎么做网站动态框网络营销的基本流程
  • ps做简洁大气网站软文推广文章范文1000
  • https的网站能做301重定向么人工智能培训心得
  • 网站定制建设哪里好优化网站排名茂名厂商
  • 免费营销型网站建设搜索风云榜入口
  • phpcms 网站名称标签想在百度上推广怎么做
  • 网站域名禁止续费我国的网络营销公司
  • 女式包包网站建设策划书今日nba战况
  • 政府网站建设会议通知seo搜索引擎优化培训班
  • 做网站的靠什么赚钱北京知名seo公司精准互联
  • 怎么做网站主导航seo宣传网站
  • 我国禁毒工作的治本之策是什么小红书seo是什么
  • 宜昌网站建设公司推广互联网推广
  • 网站开发 8g和16g山东16市最新疫情
  • 网站排名易下拉效率视频seo优化教程
  • 郑州做网站哪家最好银川网站seo
  • 手机打字赚钱一单一结seo技术培训价格表
  • 无障碍网站建设推广前景网络营销企业是什么
  • 手机网站做多宽承接网络推广外包业务
  • 东莞石龙网站建设莞网站制作微信推广多少钱一次
  • 网站建设scyiyou今日小说搜索百度风云榜