on top Qt application in windows - c++

How can I make my application always be on top meaning that the user couldn't access start menu or desktop in Qt or any other possible c++ way?
Also i need it to start right after the login progress , more like a new gui for windows , a simpler one

QWidget::setWindowFlags(Qt::WindowStaysOnTopHint) should do the trick. Note that on some window managers on X11 you also have to pass Qt::X11BypassWindowManagerHint for this flag to work correctly.

Related

Make a window stay on top and be only active window using QT/C++

I am on RHEL 6 and am creating an app using C++ and QT. I am trying to make my window/app be on top and be the only app the user can interact with.
I have set:
setWindowFlags(Qt::WindowStaysOnTopHint);
But the user can still click on a different app, which then comes to the top. I need to prevent that.
I was able to fix it by adding "show();" after I set the windowFlags.

Prevent a Windows app from stealing the focus

I have created a windows application in C++ and I want to make so whenever I run it, it doesn't steal focus from whichever window is currently focused(or maybe steal the focus and give it back right away). I'm not creating any window so i'm not sure how to change the window style, my program runs in the background.
I couldn't find any answer that worked for C++, is there any way I can do this?
When you start your application by clicking on the EXE or shortcut, Windows Explorer takes focus, not your app. The only way to start your app and not let Windows Explorer take focus is to start your program when Windows starts, via registry key.
Make sure you use the extended style WS_EX_NOACTIVATE when using CreateWindowEx().
See the Microsoft Docs for CreateWindowEx.

QT - Check if QT app is the app in focus

Here is what I want to do :
Check if my Qt app on windows is an app on the front or minimized.
If its minimized then draw the users attention by making it blink.
Now how can i detect if the app is minimized or on the background ?
I believe this is what you are looking for:
http://qt-project.org/doc/qt-5/qwidget.html#isActiveWindow-prop
then, you can call QWidget::activateWindow().
Looking at the notes:
if you are calling this when the application is not currently the active one then it will not make it the active window. It will change the color of the taskbar entry to indicate that the window has changed in some way.
This sounds exactly like this blink effect you are trying to achieve.
(Links are for Qt5, but this already exists in Qt4: http://qt-project.org/doc/qt-4.8/qwidget.html#activateWindow)

QT How to embed an application into QT widget

In our project we have three independent applications, and we have to develop a QT control application that controls these three applications. The main window will be seperated to three sub windows - each one display another one application.
I thought to use QX11EmbedWidget and QX11EmbedContainer widgets, but two problems with that:
The QX11Embed* is based on X11 protocol and I dont know if it's supported on non-x11 systems like Windows OS.
Since QT 5 these classes are not existing, and the QT documentation doesn't mention why.
So that I dont know whether to use it or not - I'll be happy to get an answers.
In addition, I see that the QT 5.1 contains QWidget::createWindowContainer(); function that in some posts it looks like this should be the replacement to the X11Embed. Can anyone please explian me more how can I use this function to create a QT widget that will run another application (a Calculator for example) inside its?
I have searched a lot in Google, and didn't find answers to my Qs.
Can anyone please help me? Am I on the right way?
Thanks!
If all three independent applications are written with Qt, and you have their source, you should be able to unify them just through the parenting of GUI objects in Qt.
http://qt-project.org/doc/qt-4.8/objecttrees.html
http://qt-project.org/doc/qt-4.8/widgets-and-layouts.html
http://qt-project.org/doc/qt-4.8/mainwindows-mdi.html
If you don't have access to them in that way, what you are talking about is like 3rd party window management. It is kind of like writing a shell, like Windows Explorer, that manipulates the state and the size of other window applications.
Use a program like Spy++ or AutoIt Spy for Windows and the similar ones for other OS's, and learn the identifying markings of your windows you want to control, like the class, the window title, etc. Or you can launch the exe yourself in a QProcess::startDetached() sort of thing.
http://qt-project.org/doc/qt-5.1/qtcore/qprocess.html#startDetached
Then using the OS dependent calls control the windows. The Qt library doesn't have this stuff built in for third party windows, only for ones under the QApplication that you launched. There are a lot of examples of doing things like this by AutoHotKey, or AHK. It is a scripting language that is made for automating a lot of things in the windows environment, and there is port for Mac as well (though I haven't tried the mac port myself).
So in the end you are looking at finding your window probably with a call like this:
#include <windows.h>
HWND hwnd_1 = ::FindWindow("Window_Class", "Window Name");
LONG retVal = GetWindowLongA(hwnd_1, GWL_STYLE); // to query the state of the window
Then manipulate the position and state of the window like so:
::MoveWindow(hwnd_1, x, y, width, height, TRUE);
::ShowWindow(hwnd_1, SW_SHOWMAXIMIZED);
You can even draw widgets on top of the windows you are controlling if you set your window flags correctly for the windows you are manipulating.
transparent QLabel with a pixmap
Cannot get QSystemTrayIcon to work correctly with activation reason
Some gotchas that come up in Windows when doing all of this, is finding out the quirks of the Windows UI when they set the Display scaling different from what you expect, and if you want to play nice with the Task bar, and handling all the modal windows of your programs you are manipulating.
So overall, it is do-able. Qt will make a nice interface for performing these commands, but in the end you are looking at a lot of work and debugging to get it in a beautiful, reliable, window manager.
Hope that helps.
I never tried it myself, but from the docs in Qt 5.1 I would try QWindow::fromId(WId id), which gives you a QWindow, which should be embeddable with createWindowContainer:
QWindow * QWindow::fromWinId(WId id) [static] Creates a local
representation of a window created by another process or by using
native libraries below Qt.
Given the handle id to a native window, this method creates a QWindow
object which can be used to represent the window when invoking methods
like setParent() and setTransientParent(). This can be used, on
platforms which support it, to embed a window inside a container or to
make a window stick on top of a window created by another process.
But no guarantee. :-)

How to keep one of my application windows on top of the other windows of the same application?

I have a Motif-based notepad-like legacy application.
I would like the modeless "Find/Replace" dialog (which is a Motif TopLevelShell) to always stay on top of the other windows of my application, but not on top of other applications.
I don't see any Motif-specific setting to do this.
KDE allows me to set window-specific behavior, but I can only make the "Find/Replace" window stay on top of all windows, which isn't right.
What is the correct way to force one of my application windows to stay on top of the other windows of the same application? Is it possible at all? Is there a way to do it in Motif? KDE? Do I have to drop down to an X call?
If you use a DialogShell then this behavior happens automatically. DialogShells are not modal by default, and do work well for file open and find/replace. Here is a quote from the Motif book:
A DialogShell is always placed on top of the shell widget that owns the parent of the DialogShell.
Dialogs are described well in chapter 5.
Sorry for being 12 years late!
You can subclass KDialog http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/classKDialog.html#10744dda705aa265a43becab32a43ea4
with Qt::WA_ShowModal attribute http://doc.qt.nokia.com/4.0/qt.html#WindowType-enum
KDialog dialog(parent, Qt::WA_ShowModal)
dialog.exec()
Maybe it's not what you want, but ...