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

网站优化的好处佛山市外贸网站建设公司

网站优化的好处,佛山市外贸网站建设公司,网页设计培训班需要多久,做外贸需要网站背景 软件的一个功能是#xff1a; 打开图片在图片上绘制序号#xff0c;序号的样式是圆圈内包含数字将带有序号的图片打印出来 实现思路也很简单#xff0c;在屏幕上显示时重写paintEvent函数#xff0c;利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应…背景 软件的一个功能是 打开图片在图片上绘制序号序号的样式是圆圈内包含数字将带有序号的图片打印出来 实现思路也很简单在屏幕上显示时重写paintEvent函数利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应的QPaintDevice切换成QPrinter就可以了。 具体来说就是利用drawEllipse绘制圆圈利用drawText绘制数字利用QFont的setPointSizeF设置数字大小以适配圆圈大小。 问题 这个功能的逻辑不算复杂在开发时没有什么问题能够正常显示和打印。 但是在测试阶段发现如下问题 屏幕上显示的序号看上去很正常但打印出的序号数字明显变小了。换了一台机器运行序号中的数字变得很大导致数字只能部分显示。 这两个问题都是字体相对于圆圈大小的问题。 原因 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对应的设备有关。 对于第一个问题屏幕绘制与打印唯一的区别就是QPainter的QPaintDevice不同所以基本可以确定问题出在QPaintDevice上。 第二个问题基本可以确认是硬件上的原因进一步推定是屏幕的原因。 一番测试后基本确定是由于QPaintDevice的DPI不同造成的。 尝试给出最小复现代码 自定义QPaintDevice实现不同DPI的QPaintDevice利用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://www.hkea.cn/news/14493215/

相关文章:

  • 高校校园网站建设的要求wordpress模板页面怎么添加图片
  • 做电话销售需要的网站集团网站建设特点互联网课堂
  • 环艺做网站天将建设集团有限公司网站
  • 网站设计到底做多宽网站开发需要多少钱推荐
  • 做网站用什么源码最好淘客商品网站怎么做的
  • 建设一个网站要多少钱上永远的吗海门城乡建设管理局网站
  • 电子商务网站建设 市场分析swf影视网站源码
  • 怎样向网站上传照片做网站现在好弄么
  • 专业外贸网站制作价格专业企业网站建设公司价格
  • 手机版网站建设多少钱有哪些免费的ppt模板下载网站
  • html5精美网站外贸公司网站建设费用报销
  • 租服务器的网站南昌有没有做企业网站和公司
  • 建一家网站多少钱redis 在网站开发中怎么用
  • 网站建设区域加盟百度广告联盟怎么加入
  • 微信微网站开发百度云vi设计作品赏析
  • 基础集团网站建设中山企业网站制作公司
  • 精仿源码社区网站源码wordpress配置qq邮箱
  • 网站右下角图片代码wordpress文章统计
  • 北京网站设计公司招聘信息福州大型网站设计公司
  • 做电商网站价钱电子商务网站建设与管理课后第四章
  • 商贸行业网站建设公司都江堰网站建设公司
  • wordpress表格图表插件下载怎样优化手机网站建设
  • 网站建设与管理必修手机wap网站如何建设
  • 网站建设还好做吗郑州网站推广 汉狮网络
  • 有域名了 怎么做网站网页设计分几个步骤
  • 辽宁省住房和建设厅官方网站短视频免费素材网站
  • 网站建设需要什么样的内容go.php wordpress
  • 制定 网站改版优化方案生成图片
  • 游戏网站建设项目规划书案例没有微信怎么进入公众号
  • wordpress 站长工具wordpress自动 插件