Why the icon is so blurry,so much little mosaic
-
I tried the icon with the svg,png,jpg and so on.I edited the icon image with the adobe illustrator .But the Pushbutton viewed stilled not very clearly.I dont know why.So what the factor influnces the looks of the qicon image.
-
@nicker-player This is not enough information to help you.
What is the size of the icon (width x height)?
On which platform?
What Qt version?
QML or widget? -
@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 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 -
@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); -
@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 ?
-
@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.