How to show taskbar icon when using QSplashScreen - c++

So I have the following code:
QString splashImageFilePath = ":/images/Splashscreens/startup.png";
QSplashScreen * splash = new QSplashScreen();
splash->setPixmap(QPixmap(splashImageFilePath));
splash->show();
splash->raise();
This runs fine and the splash screen shows up exactly like I want it to but it doesn't show an icon in the taskbar and so it is possible to click on another window and never be able to see the splash bar ever again (it hides behind other windows).
I've already tried to use the window flag Qt::WindowStaysOnTopHint but if I use this, there's still no icon in the taskbar and now it's always on top of all other windows (which I don't want).
I've looked through a few window flags so far and have googled for quite a while I'm trying to show it.
Also, I know I can give the constructor a parent, but this code is inside the main.cpp and so I don't have a way of giving it a parent window (a QWidget with an empty constructor also didn't work).
TLDR: I want my QSplashScreen to have an icon in the task bar.
Thank you in advance!

A little late, but I ran into the same problem and fixed it using WinAPI directly:
QSplashScreen splash;
splash.setPixmap(QPixmap(splashImageFilePath));
// ensure that taskbar icon is shown while the splash screen is active
int exstyle = GetWindowLong(reinterpret_cast<HWND>(splash.winId()), GWL_EXSTYLE);
SetWindowLong(reinterpret_cast<HWND>(splash.winId()), GWL_EXSTYLE, exstyle & ~WS_EX_TOOLWINDOW);
splash.show();

Related

Qt Removing Window Widgets

I'm using Qt5.5 and I would like a window without any widgets, here is a snippet from my Window constructor:
Qt::WindowFlags flags = (Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint)
& ~Qt::WindowMaximizeButtonHint;
setWindowFlags(flags);
This produces a window with no close widget and no minimize widget, however the maximize widget is still visible and can be clicked on to maximize the window, also the window can be resized by dragging the window edges.
I am trying to create a tool window that is always on top and doesn't have any widgets and is a fixed size.
In QtCreator I've set the sizePolicy to:
Horizontal Policy: Fixed
Vertical Policy: Fixed
Yet I am still able to resize the window?
I am aware that this is a very similar question to others posted before, but so far having read those and tried the suggestions nothing has worked.
I'm running on Ubtuntu 14.04.
By adding:
setFixedSize(mcintWindowWidth, mcintWindowHeight);
This fixed the problem and the maximize widget is no longer visible and the window can no longer be resized.

QT: Frameless window not animating

i need some help for my current project named "RibbonUI".
As the project name suggest, i want to implement the MS RibbonUI like in Office 2013 in QT - most stuff is working nice but i need to know something about the Qt::FramelessWindowHint.
I have subclassed the QMainWindow and added the enum value Qt::FramelessWindowHint to override the default window decoration. The buttons are implemented fine - i can minimize, maximize and close my frameless window, but the window is not animated when minimizing/maximizing/restore the window from the taskbar.
Do i have to implement the animation by myself or can i use a window manager hint or something else?
Here is a screenshot from my current work:

Wrong window painting behaviour in frameless Qt window (win32)

I have an QML application (also tested it with QWidgets, same problem) and to make it borderless (but still support the native WM features like aero snap, etc) I followed this by implementing an QAbstractNativeEventFilter and responding to the WM_NCCALSIZE signal with zero:
switch(msg->message) {
case WM_NCCALCSIZE:
*r = 0;
return 1;
...
}
I also set some window flags which are not in the Qt Namespace with
SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);
This works fine until I move or resize the window which causes Qt to rerender and a unpainted area width the width of the title and the borders appears:
Before moving/resizing
After moving/resizing
I also found a workaround for this by adding the FramelessWindowHint flag in Qt:
window->setFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Dialog);
But now this margins occurs again when the window state changes (maximizing, minimizing, ...). By blocking the WM_SIZE event for example when SIZE_MAXIMIZED is the parameter the margin doesn't appear but then I also am not able to maximize the window from Qt. This means it is a Qt side problem.
I also noticed by inspecting the window style with winspector, that after I have maximized it a new property atom appears:
Can you help me fixing this?
I think using SetWindowLong on your window handle and using the Qt Window Flags/Qt Widget Attributes is asking for trouble. You can go and look at the Qt source to see what happens when processing those window flags.
When I've created frameless windows, I've usually done it to prevent moving and resizing, because I am managing all that separately.
One problem that I had related to it, was when the On Screen Keyboard came up and docked, it would resize my windows. So besides calling resize() I had to also use setFixedSize to prevent my widget from getting manipulated when the operating system attempted to change the size of the window.
So in other words, I would add an application wide QShortcut, listening for the snapping keyboard shortcuts and resize your window the way you want it to when it happens, if you are managing a frameless window.
Hope that helps.
I wonder if this was a flaw of Qt message relay, coz I met with a similar problem which occurs on nested windows. If you press SIZE_MAXIMIZE or SIZE_MINIMIZE button of the parent window, the child window sometimes is not able to receive WM_SIZE message. I suppose there are roughly two solutions: 1. Fix Qt, 2. Work it around.
Here I have a OGL rendering child window, sometimes even the WM_SIZE message is not correctly passed. That is, if you resize parent window, you get part of the client area black.
I just use a simple workaround to fix this, which check the current size with the cached one, and make a sort of manually resize myself.

Hide main MFC window while modal dialog is active?

I have a native C++ MFC app. It has a main window based on CWnd, and user action can create a modal dialog. While the dialog is active, I want the main window to disappear, the dialog to be visible, and the main window's icon to remain in the task bar.
How can I accomplish this?
If I hide the main window (ShowWindow(SW_HIDE)), the task bar icon disappears. If I minimize the main window (SW_MINIMIZE), the icon remains. However, since the dialog is owned by the main window, this also hides the dialog.
After the dialog is created, clicking on the task bar icon makes the dialog visible. Naturally, I do not want to require the user to do this.
Even if I insert ShowWindow(SW_SHOW) in the dialog's OnInit handler, the dialog remains not visible. Spy++ shows that its visible bit is set, though. Same is true if I add SetWindowActive to OnInit.
I am not interested in changing the UI design. While the dialog is active, the user interacts only with it, and is not interested in anything in the main window. Therefore, the main window should disappear.
Using Windows VS2005 under WinXP32.
Well, in the block of code where you create the dialog and show it modal, you can do whatever you want to the main window of your app (show/hide) as long as you make the desktop window the parent of your dialog. Usually, the constructor for CDialog and derivatives takes a default argument of NULL for the parent window in which the framework ends up substituting AfxGetMainWnd(). Instead pass CWnd::GetDesktopWindow() as the parent of your dialog and then you should probably be able to hide your main window. However, you still might have a problem with the taskbar--but I'll let someone else give hints since I know nothing offhand about it.
In OnInitDialog, add following codes
//Set windows size zero, the windows disappear.
MoveWindow(0,0,0,0);
//If you want it invisible on taskbar. add following codes.
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
dwStyle &=~WS_EX_APPWINDOW;
dwStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, dwStyle);
You're fighting the OS. A modal dialog, by definition, disables but does not hide the "main" (parent) window. If you wanted another window, make a second one, but don't tell the OS to treat it as a modal dialog over the first window.
Perhaps you can resize the main window to a really small size and always keep it behind the modal dialog.

windows beneath not being painted when using a layered window

I will try to explain my problem the best i can,
I'm creating a layered window in c++ (using windowsXP), all works fine until i drag my created window near the windows start button, and then when i press the star button of windows taskbar and close it again all the windows beneath of my layered window aren't being painted (only in the area of the start window that pops over my window).
My create window is like this:
CWnd::CreateEx( WS_EX_TOOLWINDOW |
WS_EX_LAYERED,
AfxRegisterWndClass(0),
lpstr_name, WS_POPUP, 0,0,0,0,
pc_parent->GetSafeHwnd(), 0);
...
When i create the window with this styles the problem ocurrs, but if i create with the extended style WS_EX_TRANSPARENT and all the others the problem does not occur any more. And if instead of a WS_POPUP window is a WS_CHILD or WS_OVERLAPPED then this also doesn't occur...
Can anyone please explain why when i create a WS_POPUP window with the WS_EX_LAYERED style all the beneath windows aren't updated, and if i add the style WS_EX_TRANSPARENT this works fine.
Note: why i do not use the WS_EX_TRANSPARENT style if it works right? if i use it then my window can not be dragged and i need it to do it :)
Updated:
alt text http://img17.imageshack.us/img17/586/clipboard01il.jpg
The image above is to describe better what is happening:
The first part of the image you can see my leyered window and beneath is the vs, in the second img i press the start button and then in the last image i already drag my layered window to the right and you can see that the vs window does not updates the affected area.
Note that this situation until now only occurs with the start window?! with other windows it does not happen!?...
Thanks
only in the area of the start window that pops over my window
That's expected. Only that clipping rectangle is obscured by the start menu so only that region will be repainted. What behavior are you expecting? If there are windows covered by more upper level windows, then they won't be repainted either -- why repaint something just to paint over it?
All underneath windows need to get repainted though if you use transparent because GDI can't calculate the final color of the pixel without knowing the area below the window's color.