Why the icon is so blurry,so much little mosaic
-
@jsulm
the png file size is 350x350 300dpi(also tried 72dpi and the size 45x45 )
the pushbutton icon size is 38x38
i used the widget to set the icon for the pushbutton.
Qt 5.14.1 on the windows os.
So is the reason of resource files or maybe related to the codes?@nicker-player And the image file looks good if you open it in a image viewer?
Could be that down-scaling from 350x350 to 38x38 produces a bad result. -
@nicker-player And the image file looks good if you open it in a image viewer?
Could be that down-scaling from 350x350 to 38x38 produces a bad result.@jsulm
yeah the viewer looks fine,and I also tried the fixed size for the qt icon such as the 38x38.But it still looks ugly. -
@jsulm
yeah the viewer looks fine,and I also tried the fixed size for the qt icon such as the 38x38.But it still looks ugly.@nicker-player Can you try with latest Qt 5.15.x release to see whether it works better?
-
@nicker-player Can you try with latest Qt 5.15.x release to see whether it works better?
@jsulm
I think its not the version of the qt,cause I used some icons of svg,it looks well.I just want to figure out what the factor influnces the out looks of the button image.Could you tested the image for me? logo_nav.png -
@jsulm
I think its not the version of the qt,cause I used some icons of svg,it looks well.I just want to figure out what the factor influnces the out looks of the button image.Could you tested the image for me? logo_nav.png@nicker-player Looks good to me on Linux. I set it in designer. How do you set the icon?
-
@nicker-player Looks good to me on Linux. I set it in designer. How do you set the icon?
@jsulm
QPixmap pixmap;
QSvgRenderer svgRender;
svgRender.load(strText);
float w = svgRender.defaultSize().width();
float h = svgRender.defaultSize().height();
pixmap = QPixmap(w,h);
pixmap.fill(Qt::transparent);//
pixmap.scaled(w,h,Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPainter p(&pixmap);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing| QPainter::SmoothPixmapTransform);
svgRender.render(&p);
///here set the icon with using qlabel
QLabel * Icon = new QLabel(this);
Icon->setPixmap(pixmap);
Icon->setFixedSize(38, 38); -
@jsulm
QPixmap pixmap;
QSvgRenderer svgRender;
svgRender.load(strText);
float w = svgRender.defaultSize().width();
float h = svgRender.defaultSize().height();
pixmap = QPixmap(w,h);
pixmap.fill(Qt::transparent);//
pixmap.scaled(w,h,Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPainter p(&pixmap);
p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing| QPainter::SmoothPixmapTransform);
svgRender.render(&p);
///here set the icon with using qlabel
QLabel * Icon = new QLabel(this);
Icon->setPixmap(pixmap);
Icon->setFixedSize(38, 38);@nicker-player I'm confused now: you want to set a PNG file as icon but posted code to render an SVG into a pixmap. So, what do you want to do?
Also, Qt supports SVG already, I would expect that you can set SVG directly in a button, but I did not try. -
@nicker-player I'm confused now: you want to set a PNG file as icon but posted code to render an SVG into a pixmap. So, what do you want to do?
Also, Qt supports SVG already, I would expect that you can set SVG directly in a button, but I did not try.@jsulm
I also tried the png and svg files.but the forum could only support the png file.Refused me to upload the svg file.Infact I tried the png method and svg method.but seemed no difference.And what I used to set the icon for the png file is just setIcon(":/res/log_nav.png").And it confused me that I use the other pc,it looks well.So the computer screen high dpi could influnce the looks ?
-
@jsulm
I also tried the png and svg files.but the forum could only support the png file.Refused me to upload the svg file.Infact I tried the png method and svg method.but seemed no difference.And what I used to set the icon for the png file is just setIcon(":/res/log_nav.png").And it confused me that I use the other pc,it looks well.So the computer screen high dpi could influnce the looks ?
@nicker-player said in Why the icon is so blurry,so much little mosaic:
So the computer screen high dpi could influnce the looks ?
Yes, it does. Use QPixmap::setDevicePixelRatio() to set the scaling from your HiDPI display (e.g. if it is set to 150% on Windows, use 1.5 as a factor here).
-
@nicker-player said in Why the icon is so blurry,so much little mosaic:
So the computer screen high dpi could influnce the looks ?
Yes, it does. Use QPixmap::setDevicePixelRatio() to set the scaling from your HiDPI display (e.g. if it is set to 150% on Windows, use 1.5 as a factor here).
You should update to 6.7 to get proper High-DPI support. Qt5 had a lot of issues with that.