Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to develop python qwidget for c++ QMainWindow?
Forum Updated to NodeBB v4.3 + New Features

How to develop python qwidget for c++ QMainWindow?

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 4 Posters 243 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MonkeyBusiness
    wrote on 19 Feb 2025, 09:40 last edited by
    #1

    Want to code some python qwidget for my c++ MainWindow design. How to do so?

    J 1 Reply Last reply 19 Feb 2025, 11:41
    0
    • M MonkeyBusiness
      19 Feb 2025, 09:40

      Want to code some python qwidget for my c++ MainWindow design. How to do so?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Feb 2025, 11:41 last edited by
      #2

      @MonkeyBusiness said in How to develop python qwidget for c++ QMainWindow?:

      Want to code some python qwidget for my c++ MainWindow design

      Why? What is actually your use case?
      You can execute Python code from C++ like explained here: https://docs.python.org/3/extending/embedding.html
      But this will not work with Python and QWidgets because to execute Python code in a C++ application Python interpreter is called.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 20 Feb 2025, 01:30
      1
      • J jsulm
        19 Feb 2025, 11:41

        @MonkeyBusiness said in How to develop python qwidget for c++ QMainWindow?:

        Want to code some python qwidget for my c++ MainWindow design

        Why? What is actually your use case?
        You can execute Python code from C++ like explained here: https://docs.python.org/3/extending/embedding.html
        But this will not work with Python and QWidgets because to execute Python code in a C++ application Python interpreter is called.

        M Offline
        M Offline
        MonkeyBusiness
        wrote on 20 Feb 2025, 01:30 last edited by
        #3

        @jsulm hi, I would like a c++ pointer to the created python QWidget to be add to my c++ mainwindow.

        P 1 Reply Last reply 20 Feb 2025, 01:48
        0
        • M MonkeyBusiness
          20 Feb 2025, 01:30

          @jsulm hi, I would like a c++ pointer to the created python QWidget to be add to my c++ mainwindow.

          P Offline
          P Offline
          Pl45m4
          wrote on 20 Feb 2025, 01:48 last edited by
          #4

          @MonkeyBusiness said in How to develop python qwidget for c++ QMainWindow?:

          I would like a c++ pointer to the created python QWidget

          But why?
          Either write the rest of the GUI also in Python or rewrite the widget in C++.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CristianMaureira
            wrote on 1 Apr 2025, 13:25 last edited by
            #5

            Hello @MonkeyBusiness
            The use case you are describing is not very usual, and that's why you might have find difficult to do it.

            As stated before, you can embed a Python interpreter within your C++ application, which can help you to have a Python interface that can interact with some of the C++ objects of your application.
            This is known as making a Qt/C++ application scriptable with Python.

            You could create a QWidget from Python, and display that like a QMessageBox, QLabel, QTreeWidget, etc, but that requires a bit more work, because that needs a runtime registration of the bindings to be generated.

            There has been some internal work on dynamic Python bindings within C++ applications, but it's not released yet.

            Like other recommendations, it seems that you can rely on .ui files for easily creating interfaces for your C++ application, rather than trying to expose python widgets to C++.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved