Qt Tray Icon Drag and Drop - c++

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.

Related

Suggestion wanted for MFC custom scrollbars

I want to make my own scrollbars for a custom drawn plot, like this image, what would be the best way to go?
Scrollbars should:
Only be visible when mouse hover over it (with fade in/out)
Be a part of the x/y axis of the plot, like in the picture
Not have any arrow buttons, just the thumb Thinner than the normal scrollbars
Would you suggest to:
Create everything from scratch, handling paging, scrollwheel etc.
Try to inherit CScrollBar and do my own drawing?
From what I've read, it's not very easy to customize scrollbars in MFC, for example here)
First off, these have to be scrollbar (or other) controls, not window scrollbars (used for scrolling a window).
Second, the statement "it's not very easy to customize scrollbars in MFC", is only partially true. MFC is a "thin wrapper" of Windows API, so you should better refer to the documentation of the Windows scrollbar control.
Then there is the CScrollBar class, but took a short look, and indeed, it does not really offer anything more than the Windows scrollbar does. As for the sample in the link you posted is a new (custom) control (painting everything on its own), i.e. literally "from scratch", not inheriting anything from CScrollBar.
So, you have to look into the Windows scrollbar control, and what it offers. Did take a look, and saw few things. Unfortunately there seems to be no owner-draw functionality. You can process the WM_CTLCOLORSCROLLBAR message, but this only allows you to change colors.
And according to the documentation the background color only. This appears to be the only possible customization, apart from the SBM_ENABLE_ARROWS message, which can hide the arrows. And no fading effect. If these are enough to you, you could try the Windows/MFC scrollbar, otherwise try writing your own.

Widgets in window title Qt

Is in Qt something like GTK.headerbar or any other possibility to add wiget (button for example) in window title?
Thanks in advance.
Short answer is 'no', Qt doesn't implement any kind of window decorations (except QWS which is a different story).
In Linux the title bars (window decorations) are carried by Window Managers, like Metacity or Compiz. Windows and OSX use their own window decorations. Qt has almost no control over what happens on the window title bars.
Gnome3/GTK3 (and not Gnome2) allows you to use widgets in the title bar but it's not the case for many other Desktop Environments / Window Managers. Your options are:
Use the API provided by the window manager / OS
Pros: native look.
Cons: you need to maintain separate implementation for each OS / DE. Not all support doing such.
Hide window decorations and implement you own
Pros: code once, use everywhere. Google Chrome and Vivaldi do that, for example.
Cons: you need to implement window resize and move
Use an overlay widget on top of the system title bar that will always follow the window
Pros: pretty much straightforward to do but I don't recommend it.
Cons: the widget will always lag when moving the main window. Native look still has to be implemented. Take into account that user can switch the theme and the widget will look odd.

Constraining other application's window sizes through Qt Application

I'm looking for a way in Qt to constrain other application window's (some will not be Qt) so that when maximized don't overlap my Qt application. Essentially I want to create the Windows Taskbar. I'd like the applications edge to dock to the appropriate edge of my Qt Taskbar in the same way that applications dock to the Windows taskbar when they are maximized. I envision this taskbar to exist along the top edge of the screen, but would like to allow users to decide which edge it will live on.
I know it isn't hard to make a window that is always on top it's more the auto docking issue I'm having a hard time figuring out.
I'm right now only looking to accomplish this on Windows.
Thank for any help.
Detailed explanation on how to do it would be too long for an answer here, but MSDN documentation on SHAppBarMessage should get you started. Taskbar created like that can even be part of winows taskbar ;)

Needed: A popup window without a taskbar icon

I am designing a UI engine that needs to render into popup (WS_POPUP) windows. As these windows cannot be children of other windows, each instance is given its own taskbar icon.
I need a way to prevent the taskbar icons from appearing for certain windows that are created as "dialogs". I cannot use an OS-provided dialog because they all have frames (and I can't figure out how to render into them) or a tool-created custom dialog (which seem to require the CLR).
I am not an expert with the windows API and I feel that I have missed something obvious...
Also: Anything involving CLI/CLR is not an option.
EDIT:
The WS_EX_NOACTIVATE style can be used for this purpose as well, though the activation behavior would need to be emulated by the program.
If you set the WS_EX_TOOLWINDOW extended style for your window, it won't be shown in the task bar or Alt+Tab list. This does cause the window to be rendered slightly differently, however (thinking floating tool palette).

Creating a custom context menu Window (WinAPI)

I'm wondering how to create windows like these alt text http://img824.imageshack.us/img824/997/this.jpg
I'm refering to the one that says Marquee selection tool... these ones. I'm also not referring to the skin. I know how to do my own drawing and what not, this is not the issue. It's because windows usually need a parent which means it should not be possible for these windows to overlap into the tools. The only windows that can do this are context menus and menus. How can I create this style of window? Thanks
I think you are confusing the concept of owner windows and parent windows. Only dialog controls have parent windows, and these are automatically clipped by the parent's client area. Other windows have owner windows. This is a weaker relationship. There's nothing stopping a window from overlapping its owner.
Also, I wouldn't assume that just because the toolbar launches the context menu that the toolbar window has a relationship with the menu window. It might or might not, depending on how things are coded behind the scenes.
In any case, just try it out. Use the TrackPopupMenu() to create a popup. You can have it overlap the owner window without difficulty. Any window without the WS_CHILD style will exhibit the same behaviour.