Results 1 to 9 of 9

Thread: HWND on Win32 API to Qt widget

  1. #1
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default HWND on Win32 API to Qt widget

    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
    Last edited by delio; 26th March 2014 at 10:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HWND on Win32 API to Qt widget

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    delio (26th March 2014)

  4. #3
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: HWND on Win32 API to Qt widget

    Quote Originally Posted by wysota View Post
    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!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HWND on Win32 API to Qt widget

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    delio (26th March 2014)

  7. #5
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: HWND on Win32 API to Qt widget

    Last edited by delio; 26th March 2014 at 11:54.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HWND on Win32 API to Qt widget

    It won't work with Qt5. And even if it did, it would require a running Qt event loop anyway.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: HWND on Win32 API to Qt widget

    Thanks for your answers!

  10. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: HWND on Win32 API to Qt widget

    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,

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: HWND on Win32 API to Qt widget

    Quote Originally Posted by anda_skoa View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. hwnd to qwidget setparent error
    By cic in forum Qwt
    Replies: 1
    Last Post: 27th August 2013, 14:40
  2. Converting from Qt's WId to Windows HWND?
    By ComServant in forum Newbie
    Replies: 3
    Last Post: 27th December 2012, 18:26
  3. Get HWND of QGLWidget
    By pl01 in forum Newbie
    Replies: 2
    Last Post: 19th December 2010, 21:18
  4. Reparenting widget to Win32 application
    By RThaden in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2009, 18:21
  5. Can I paint on Qt widget by invoking win32 sdk api?
    By mendynew in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2008, 01:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.