svg icons appears pixelated on high DPI - c++

Some of my SVG icons don't scale properly on scaling a monitor (Win10) or use a highDPI monitor (Win10, Linux, Mac). This applies to icons assigned to a QAction and displayed by QMenu entries or QToolButtons, and icons assigned to QDockWidgets, as shown in the upper part of the attached screenshot.
The icons in the lower part are painted in the derived paintEvent(..) and render perfectly.
Using the option QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); The system seams to use some scaling heuristic on a pixmap so the icon becomes somehow edgy:
Is there any way to make qt redraw the icon on the SVG base without the need to derive all icon-showing classes?
Sincerely
JJ

I had this issue with SVG icons too. Turns out for me it was caused by an aspect ratio difference between the SVG file and what I tried to render it as. I tried to render as a square but my SVG file was not square. Setting square dimensions in the SVG file fixed it.

Related

Qt widget blurred semitransparent background on Linux

Working with widgets, c++ and Linux
need something kind of:
this
but no borders and custom title.
Search for a few days, but nothing.
For now, there is a widget with setWindowFlags(Qt::FramelessWindowHint); and a peace of qss for semitransparent background. How can I blur it? Is is possible at all?
I do not think this can be done with Qt. Blurring can be done using https://doc.qt.io/qt-5/qgraphicsblureffect.html but it is only limited to the widgets painted by Qt. Which the underlying background is not, even if you manage to make your widgets transparent or semitransparent. Painting the background is always the business of the operating system (or window manager) and not the business of your application Qt.
You can certainly try to do some extreme hacking like grabbing the active screen before your window is displayed (see How to capture the current screen image using Qt?) then getting certain rectangle content of the image, which corresponds to the background of your window, then paint it blurred to the background of your application and then update it everytime you move or resize your window... But anyway, even if you manage this, this background will be static and not dynamic.
I recommend that you abandon the idea of blurry background and leave this function to the window manager and the operating system.

Qt: Bad window icon quality

I'm using Qt 5.10.1. I created a window icon resource and applied to Qt application like following:
a.setWindowIcon(QIcon(":/icons/resources/logo_icon.png"));
The size of logo_icon.png is 256*256.
The result is this:
The icon is a little blurrly, which is not what I expected. For comparison, following is the window icon of GIMP in which I designed the icon:
I tried various sizes of the image from 16*16 to 256*256, there was no luck. Changing image format to ico from png also didn't work.
What should I do to render a clearer window icon?
Maybe in the ui file of your window there is a iconSize value that makes your icon scale not very well when rendered by the window manager. This blurry effect occurred to me sometimes because the size was 15 px instead of 16 (or another power of 2).
Try to open the .ui file of your main window in Design mode and look under the QMainWindow group in the widget properties panel to set the iconSize to something like 16.
You can also set the icon file from there, using the windowIcon property under the QWidget group.

drawing inside a qt windows

I'd like to draw a color "frame" within a QT window. So, I have
setFixedSize(WIDTH, HEIGHT);
and I'd like to draw, say, a red (filled) border within width and height. Could anyone help me out?
Depends on a couple of things:
Is it a border around an existing widget? If it's just a border around an existing widget don't go down the route of painting it yourself, it's much simpler to use Stylesheets than draw it.
If of course you need a custom or very specific style, then you're best off drawing it using the Painting System. I'd strongly suggest do it using stylesheets unless you do need specifics. The paint system can be a bit unwieldy for just adding a border to a widget.

Customize QScrollBar intersection using stylesheet Qt

I’ve already customize my horizontal and vertical scrollbars using a stylesheet no problem.
But there still an annoying tiny area which remains blank :
The intersection of an horizontal and vertical bar. A small rectangle.
How could I change its color ? (Using stylesheets )
Thank you !
Qt 4.7.1 on Mac OSX Snow Leopard
Ps: Even on the Qt stylesheet example it’s still white.
I realise this is an old question, but I found a better solution.
QAbstractScrollArea::corner {
background: somecolor;
}
Or, to hide it, use:
background: transparent;
By default, the scroll area corner will be painted with the Window palette. Unfortunately, you cannot change the Window palette using only stylesheets. However, what you can do is create a dummy widget and set it to be displayed in the corner area with QAbstractScrollArea::setCornerWidget(QWidget *widget), and then use the stylesheet to change the color of that widget.

Custom draw CTreeCtrl: how to add font strike through?

I have implemented custom draw for an CTreeCtrl in my MFC Smart Device program. I have successfully changed the color of specific nodes of the CTreeCtrl. I am now trying to understand how to get the default font used to draw text in the control so I can add a strike-through to the font for certain nodes. How would I go about getting the default font used to draw text in the CTreeCtrl and apply a font strike-through to the font?
Use GetFont() to get the font of the control. Strike-through can't be done with ::DrawText AFAIK, but it's easy to just add a GoTo()/LineTo(). You can use GetTextExtent() to get the size of the bounding rectangle and derive the left/right of the strike through line from that.