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.
Related
In my qt application, I am using a QDock widget which, whenever dragged to change its size, messes up the icon and color on the handle.
My stylesheet for the splitter is:
QMainWindow::separator:vertical,
QSplitter::handle:horizontal {
image: url(icon:/primary/splitter-horizontal.svg);
}
same for the horizontal splitter.
GIF of the issue is here, as it is difficult to describe.
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.
I have created some (CMFCToolBar) toolbars and added buttons and icons to them. I read on Microsoft's official website that CMFCToolBar takes 23x22 button size and 16x15 icon size (ref: link).
If I use 16x15 for the icons, then icons appear blurry. This is because the icons are originally with size 16x16. I used the function SetSizes(CSize (23,23), CSize(16,16)) to change icon size but the icons do not appear right:
Is there another way to set icon and button size?
Update
I called the SetSize function before create toolbar but the icon still appear a little blurry:
I want to know if there is a way to set Icon/button Transparent or make it clear like we can set toolbar transparent through TBSTYLE_TRANSPARENT in CreateEx function.
SetSizes is a static function that affects the complete library.
It should be called before you create any toolbar or menu object.
Best location is in InitInstance of you applicxation.
But my tipp: Use the sizes that are recommended! 16x15 and 23x22....
Transparency can be done with standard 32bit RGB/A bitmaps.
If you have a 16 color bitmap you should use RGB(192,192,192) as the standard color for the background. It is automatically replaced with the needed background color.
This has been answered here too.
when I create a window with the Ui Designer in QtCreator, most default templates give me a somewhat blank grey frame. There are options for adding more frames like that on the inside, but how do I add the default blue ribbon on the top with the window title, icon, minimize, maximize and close buttons? There is no option for that anywhere.
Generally, you don't - that's up to the operating system.
You can preview the window style with various skins in creator - select the skin under tools->options->designer->forms, check Print/Preview Configuration and there are various options for Style and device skins.
There are some options regarding window style under QMainWindow as well, for instance unifiedTitleAndToolBarOnMac, but it is best to leave the outer window to the OS.
I am creating a MFC CDialog and adding a bitmap in a picture control and I have edit controls that need to be placed relative to positions on the image. However the size of the image in the picture control changes when I run my application.
This makes it difficult to align my edit boxes with the image.
Can anybody tell me why this happens?
There is no code to post as this is entirely done in the dialog editor of VS2013.
Windows adjusts the size of dialogs to match the system font, which can be changed by the user. For information about this look up dialog base units. If you need your dialog layout to match a bitmap then you need to override the Windows adjustment and explicitly set the size and location of the controls at run time. That would mean that in OnInitDialog you use MoveWindow on the dialog itself and on every control to set their size and location in pixel units that match the bitmap.