查看完整版本: [-- Qt svg图标缩放的问题 --]

QTCN开发网 -> Qt基础编程 -> Qt svg图标缩放的问题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

snow_man_0 2020-11-27 22:34

Qt svg图标缩放的问题

[attachment=22096]这是16*16的PNG图片
[attachment=22097]这是24*24的svg图片,用QIcon("filename.svg")放在菜单上后,缩小成16*16,图片不清楚,上面的英文文本颜色还变了

用QSvgRender和QPixmap生成16*16的QIcon,还是一样,QSvgRender读出来就是黑色文本
本以为SVG图片在缩放时能保持清楚度,想一劳永逸,用一张svg图片代替多个尺寸的PNG。不知道问题出在哪?是Qt对SVG支持不够吗?

zy1233 2020-11-30 09:02
QPixmap pixmap("filename");
QPixmap fitpixmap=pixmap.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

snow_man_0 2020-12-01 00:28
zy1233:QPixmap pixmap("filename");
QPixmap fitpixmap=pixmap.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); (2020-11-30 09:02) 

读出来就是黑的啊

zy1233 2020-12-01 09:42
你读取svg的代码贴一下?

snow_man_0 2020-12-01 18:15
zy1233:你读取svg的代码贴一下? (2020-12-01 09:42) 

    //QImageReader ir(":/_noinclude/resource/SegyToText.svg");
    //QImageReader ir("E:/engineer/GeoDataProcess/code/DataFormatConversion/SegyToText/_noinclude/resource/SegyToText.svg");
    //auto ic = new QIcon(
    //    QPixmap::fromImage(ir.read(), Qt::ColorOnly));// .scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

    //QPixmap pixmap(16, 16);
    //QPainter qPainter(&pixmap);
    //QSvgRenderer m_svgRender;
    //    
    //m_svgRender.load(QString("E:/engineer/GeoDataProcess/code/DataFormatConversion/SegyToText/_noinclude/resource/SegyToText.svg"));
    //m_svgRender.render(&qPainter, QRectF(0, 0, 16, 16));

    //auto ic = new QIcon(pixmap);
    //return ic;
    //QPixmap pixmap(":/_noinclude/resource/SegyToText.svg");

    //return new QIcon(pixmap.scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

    return new QIcon(":/_noinclude/resource/SegyToText.png");

都试过了,感觉Qt对svg中的text对象支持不太够

zy1233 2020-12-02 09:30
snow_man_0:    //QImageReader ir(":/_noinclude/resource/SegyToText.svg");
    //QImageReader ir("E:/engineer/GeoDataProcess/code/DataFormatConversion/SegyToText/_noinclude/resource/SegyToText.svg");
   .. (2020-12-01 18:15) 

  QPixmap pixmap(16, 16);
  QPainter qPainter(&pixmap);
  pixmap.fill(Qt::transparent);//设置背景透明
  QSvgRenderer m_svgRender;
  
  m_svgRender.load(QString("E:/engineer/GeoDataProcess/code/DataFormatConversion/SegyToText/_noinclude/resource/SegyToText.svg"));
m_svgRender.render(&qPainter, QRectF(0, 0, 16, 16));

试一下这个,我记得我以前用svg是直接QIocn("xxx.svg")

snow_man_0 2020-12-02 21:17
zy1233:  QPixmap pixmap(16, 16);
  QPainter qPainter(&pixmap);
  pixmap.fill(Qt::transparent);//设置背景透明
  QSvgRenderer m_svgRender;
....... (2020-12-02 09:30) 

文本还是黑的
背景透明的问题,Qt5.15好像修复了。主要是带字体的文本对象,Qt svg模块对标准支持不够

zy1233 2020-12-03 10:25
snow_man_0:文本还是黑的
背景透明的问题,Qt5.15好像修复了。主要是带字体的文本对象,Qt svg模块对标准支持不够 (2020-12-02 21:17) 

好吧,官方说支持SVG1.2Tiny,那就只能试一下 用QImage替换QPixmap把,好像可以指定RGB fromat


查看完整版本: [-- Qt svg图标缩放的问题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled