https://github.com/forderud/qtnativewindow
Sample code for embedding non-Qt UI in a Qt application and vice versa
https://github.com/forderud/qtnativewindow
qt windows
Last synced: about 1 month ago
JSON representation
Sample code for embedding non-Qt UI in a Qt application and vice versa
- Host: GitHub
- URL: https://github.com/forderud/qtnativewindow
- Owner: forderud
- License: mit
- Created: 2024-06-10T08:02:20.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-20T14:40:15.000Z (almost 2 years ago)
- Last Synced: 2025-06-03T01:43:16.337Z (about 1 year ago)
- Topics: qt, windows
- Language: C++
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Sample code for **embedding non-Qt UI in a Qt application**. Emphasis is put on native windows and OLE controls with transparent background.
Screenshot:

Window hierarchy with [extended window styles](https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles):

## Discovered issues
### Qt foreign window flickering
[QTBUG-126280](https://bugreports.qt.io/browse/QTBUG-126280): The semi-transparent foreign windows showing green & blue circles will *flicker when the main window is resized*. This is currently worked around by manually setting `WS_EX_COMPOSITED` on the parent Qt window. However, this feels like a hack that leads to other drawing artifacts.
Stop defining `AVOID_FLICKERING_WITH_COMPOSITED_WINDOW` to reproduce this issue.
### Qt OLE control transparency problem
[QTBUG-132671](https://bugreports.qt.io/browse/QTBUG-132671): How to create a semi-transparent ActiveQt window?
[QAxWidget](https://doc.qt.io/qt-6/qaxwidget.html) doesn't seem to handle OLE controls with transparent background properly. This leads to drawing artifacts where the background is not cleared.
## Prerequisites
* [Visual Studio 2022](https://visualstudio.microsoft.com/)
- Select "Desktop development with C++" workload.
- Select "C++ MFC for latest v143 build tools (x86 & x64)" component.
* [Qt SDK](https://www.qt.io/product/development-tools) (any recent version)
- Select "Active Qt" component.
* [Qt VS Tools](https://doc.qt.io/qtvstools/)
## Qt documentation
* Qt [Window Embedding](https://doc.qt.io/qt-6/platform-integration.html#window-embedding)
* [QWindow::fromWinId](https://doc.qt.io/qt-6/qwindow.html#fromWinId)
* [QWidget::createWindowContainer](https://doc.qt.io/qt-6/qwidget.html#createWindowContainer)
* [Using ActiveX controls and COM in Qt](https://doc.qt.io/qt-6/activeqt-container.html)
## Microsoft resources
* Raymond Chen: [I used WS_EX_COMPOSITED to get rid of my redrawing flicker, but it resulted in sluggish response](https://devblogs.microsoft.com/oldnewthing/20171018-00/?p=97245) - explains that `WS_EX_COMPOSITED` relies on the release the device contexts (DC) _or_ `EndPaint` calls to detect that rendering have completed.