QT: Different dpi behavior for different widgets - c++

I have two widget inside of one window.
First widget is a program main menu.
Second one open when user presses 'New project' button.
I have enabled DPI via QT_SCREEN_SCALE_FACTORS + setAttribute(UseHighDpiPixmaps).
I have icons dynamically scaled for second widget when I move app from one monitor (windows dpi 100%) to another monitor (windows dpi 175%).
But first one (main menu) does not work this way.
It just preserves 2x icons without any respect to DPI.
I found this by marking 2x icons.
Also I was not able to reproduce this on the toy example.
Could anyone please point me the right direction?

Related

How to set font to the Popup Menu?

I have an issue with showing Popup Menu in a Windows application. I have no opportunity to set it's font size. I need to do this, for example, when I have two monitors with different DPI and want to show the menu at the monitor with a DPI different from the system DPI. The application I create uses Per Monitor DPI Aware manifest.
I know that in Windows 10 it's possible to create menu with a particular DPI Awareness Context so it will be bitmap stretched (found the information here), but I would like to not to stretch anything. In addition, creating menu with a System or Unaware DPI Aware Context leads to it's incorrect behavior like bad mouse positioning in the menu.

Image in picture control in MFC dilaog is larger when running applicaiton than is shown in dialog editor

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.

QPushButton is inactive till MainWindow gets focus

I have a QMainWindow with three QPushButtons (arranged in a QVBoxLayout in a QWidget). All have the same properties, except objectName, icon and iconSize. All are enabled and have two icons, one for normal and one for disabled.
When I start my application, always the top most icon shows the disabled icon (but is working, so it is enabled) the other two are fine. As soon as a focusable control in that window gets the focus, the icon changes to the active one and everything is fine.
Calling update or repaint in the showEvent of the window doesn't help either.
I'm using gcc 4.8.1 and qt 5.1.0.
Any ideas how to handle this glitch?
Update: It gets more strange: Starting the program, the icon shows disabled, getting another application the focus, the icon shows enabled, bringing the window on top again without giving it the focus (e.g. by using the task bar) changes the icon back to diabled. Clicking a control in the window, which can have focus will fix it again.
Well, well I finally got it. I just set the focus manually in the code and realized, that the icons were set in a wrong way. If a button was currently focussed it displayed the disabled icon. I had messed up the different button states and too many states got the disabled icon.

Wrong scaled up icon in taskbar of a Win32 application on Windows 7

I have a UI C++ Win32/WTL app. I have an application icon with many embedded sizes, including 16x16, 32x32, 48x48 and 64x64. I do a SetIcon() for both small and large icons and yet my Windows 7 task bar shows a blurry scaled up icon.
Are there any special APIs that need to be called or some special considerations?
The icon shown in the taskbar is not the one you set with SetIcon() but the one that explorer also shows for the exe file itself. That means it shows the very first icon in your exe resources.
Change the resource ID of your icon to e.g. 1 so it's the first icon, or add other sizes to the first icon your exe currently uses.
Icons are in the order? I have information, that Windows use icons in direct order. Try place icon 64x64 in the first place in array.
Unusual DPI / font size setting? I've seen XP ask for a 20x20 icon.

Qt Tray Icon Drag and Drop

Does anyone know if it is possible to use drag and drop with a tray icon using Qt?
I've been doing some research and here is what I have come up with:
A QSystemTrayIcon cannot explicitly handle a drag/drop event. However there is a workaround based on the Spifftastic tray icon location method.
You create a uniquely colored icon
and place it as the icon for a brief
moment and take a screenshot of it.
Given that you know the color
sequence for the icon, you can
search through the screenshot and
locate the particular icon's
location.
A transparent widget is positioned
over the icon and is used as the
drop target.
I have yet to work at a few of the finer details of the operation but that is the gist of it. All things considered it is a hacky way of things but given that there are no other ways to do this I think it is acceptable.
Fluffy App (written in C#) uses the Spifftastic method to locate the tray icon. I'm assuming the part about the transparent window is how they accomplish that but I have yet to decompile and examine their system.
Since QSystemTrayIcon is a QObject, not a QWidget, my guess is this is not possible. The system tray icon isn't really owned by Qt - it's passed on to the 'desktop', i.e whatever part of the Gnome/KDE/Windows/Mac is drawing the relevant area. At least on Mac, you'd be dropping on the menu-bar, which would be a very strange UI. For Gnome and KDE it's a FreeDesktop.org standard, but again I don't think its your process which actually does the drawing, and hence there's no way for Qt to get events such as drag and drop to you.