PDA

View Full Version : HWND on Win32 API to Qt widget



delio
26th March 2014, 10:01
I've write win32 API program but GUI creating is too hard and ugly for me.
So I want Qt GUI but I have to use Win32 command.

How to convert HWND on Win32 API to Qt widget?
I know that I have to use QWidget::winId().
but I don’t know how to write it
Please give me an example.

Thanks

wysota
26th March 2014, 10:54
If you expect to pass a winapi handle to an existing window to QWidget to be able to use nice Qt drawing API but handle everything else using only winapi code then it doesn't work this way. What you can do instead is that you can base your application on Qt and use WinAPI calls for things unrelated to GUI if you want. Just be aware this is more complicated than just passing handles around.

delio
26th March 2014, 11:39
If you expect to pass a winapi handle to an existing window to QWidget to be able to use nice Qt drawing API but handle everything else using only winapi code then it doesn't work this way. What you can do instead is that you can base your application on Qt and use WinAPI calls for things unrelated to GUI if you want. Just be aware this is more complicated than just passing handles around.

If I do that instead, I have to fix all my code. Because library that I use (SFML) has to use complicate code (if I want to use event handler)
Anyway better?

-->Can I use QToolbar and others widgets in Win32 API?

Thanks for answer!

wysota
26th March 2014, 11:42
Qt widgets require a Qt event-loop running therefore to use anything widget-related your application needs to be more tightly integrated with Qt. If you just want the drawing API, you can draw on QImage and convert the output to something you can render with WinAPI but there is not much sense in doing that.

delio
26th March 2014, 11:47
Ok, but I found this
http://doc.qt.digia.com/solutions/4/qtwinmigrate/winmigrate-qt-in-win32-example.html
https://qt.gitorious.org/qt-solutions/qt-solutions/source/fd22bee22274975c56f1c10d87ee9fd2c0818f83:qtwinmigr ate/examples/winhost/main.cpp#L83

It will work? Or Is it too old?

wysota
26th March 2014, 11:54
It won't work with Qt5. And even if it did, it would require a running Qt event loop anyway.

delio
26th March 2014, 11:58
Thanks for your answers!

anda_skoa
30th March 2014, 11:38
You can embed a native window using QWindow::fromWinId(). This is called the "foreign window" capability. The QPA (Qt Platform Adapter) for Windows has that capability.

Cheers,

wysota
30th March 2014, 15:29
You can embed a native window using QWindow::fromWinId(). This is called the "foreign window" capability. The QPA (Qt Platform Adapter) for Windows has that capability.

I think OP wants to embed Qt widgets into his non-Qt app.