Results 1 to 5 of 5

Thread: how to make python Qwidget for c++ QtMainWindow?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,332
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    317
    Thanked 871 Times in 858 Posts

    Default Re: how to make python Qwidget for c++ QtMainWindow?

    If you are using PySide, then the PySide QWidget has a method winId() which returns a wId handle to the underlying window system window handle (like an HWnd in native Windows code).

    On the C++ side, the static method QWidget::find() takes a wId as argument and returns a QWidget pointer. So this could be the solution for you.
    Last edited by d_stranz; 20th February 2025 at 16:56.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Feb 2025
    Location
    Camden, OH
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to make python Qwidget for c++ QtMainWindow?

    You can embed a Python-based QWidget into a C++ QMainWindow by exposing the QMainWindow's addWidget function using Python bindings. This is typically done with PySide6 or PyQt6.

    Steps:
    1. Expose C++ functions to Python: Use Shiboken (for PySide6) or SIP (for PyQt6) to create bindings for QMainWindow’s addWidget function.
    2. Embed Python in C++: Use CPython API (Py_Initialize(), PyImport_ImportModule(), etc.) to run Python code inside C++.
    3. Create Python UI Components: Design QWidget in Python and expose it to C++.
    4. Load Python Widgets in C++: Use the exposed functions to add Python-based QWidget dynamically.

Similar Threads

  1. Python / PyQt5 MDI Window focus problem
    By apereira in forum Newbie
    Replies: 5
    Last Post: 21st September 2015, 23:29
  2. Replies: 3
    Last Post: 14th February 2012, 15:47
  3. initial size of docked window
    By GrahamLabdon in forum Newbie
    Replies: 3
    Last Post: 28th February 2011, 15:33
  4. Docked main window
    By ahmed963 in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2008, 21:45
  5. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43

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
  •  
Qt is a trademark of The Qt Company.