QT How to embed an application in a QT widget

In our project, we have three independent applications, and we need to develop a QT management application that manages these three applications. The main window will be divided into three under the windows - each of them displays a different application.
I thought to use QX11EmbedWidget and QX11EmbedContainer widgets, but two problems with this:

  • QX11Embed * is based on the X11 protocol, and I do not know if it was supported on systems other than x11, such as Windows.
  • Since QT 5, these classes do not exist, and the QT documentation does not mention why.

So I don’t know whether to use it or not - I will be glad to receive answers.
In addition, I see that QT 5.1 contains the function QWidget :: createWindowContainer (); , which in some posts looks like it should be an X11Embed replacement. Can someone please explain more to me how I can use this function to create a QT widget that will launch another application (for example, a calculator) inside?

I searched a lot on Google and did not find the answers to my questions.
Can anyone help me please! Am I on the right track?
Thanks!

+7
c ++ qt qwidget
source share
2 answers

If all three independent applications are written with Qt, and you have their source, you can only combine them through parental control 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 do not have access to them this way, then what you are saying is like managing third-party windows. This is similar to a shell entry, such as Windows Explorer, that controls the state and size of other windowed applications.

Use a program such as Spy ++ or AutoIt Spy for Windows and similar for other operating systems, and study the identification markings of your windows that you want to control, for example, class, window title, etc. Or you can run exe yourself in QProcess::startDetached() .

http://qt-project.org/doc/qt-5.1/qtcore/qprocess.html#startDetached

Then, using OS-dependent calls controls the windows. The Qt library does not have this material built-in for third-party windows, only for those that you launched in QApplication. There are many examples of actions such as AutoHotKey, or AHK. This is a scripting language that is designed to automate many things in a Windows environment, and there is a port for Mac (although I have not tried the Mac port itself).

So, at the end, you look at your window, probably with this call:

 #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 as follows:

 ::MoveWindow(hwnd_1, x, y, width, height, TRUE); ::ShowWindow(hwnd_1, SW_SHOWMAXIMIZED); 

You can even draw widgets on top of windows that you control if you correctly set the window flags for the windows you manage.

transparent QLabel with pixmap

Cannot get QSystemTrayIcon to work correctly with activation reason

Some errors that Windows encounters when doing all of this reveal the quirks of the Windows user interface when they set the display scale to what you expect and if you want to play well with the taskbar and handle all the modal windows of your programs that you manage.

So in general, he can. Qt will make a nice interface for executing these commands, but in the end you look at a lot of work and debugging to get it in a beautiful, reliable window manager.

Hope this helps.

+8
source share

I have never tried this myself, but from the docs in Qt 5.1 I would try QWindow :: fromId (WId id), which gives you a QWindow that should be nested in createWindowContainer:

QWindow * QWindow :: fromWinId (WId id) [static] Creates a local view of a window created by another process, or using the native libraries below Qt.

Given the handle identifier for the native window, this method creates a QWindow object that can be used to represent the window when calling methods such as setParent () and setTransientParent (). This can be used on platforms that support it, embed a window inside the container, or make a window above the window created by another process.

But no guarantees. :-)

+6
source share

All Articles