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?
QtWS25 Last Chance

How to develop python qwidget for c++ QMainWindow?

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 4 Posters 213 Views
  • 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 last edited by
    #1

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

    jsulmJ 1 Reply Last reply
    0
    • M MonkeyBusiness

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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      1
      • jsulmJ jsulm

        @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 last edited by
        #3

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

        Pl45m4P 1 Reply Last reply
        0
        • M MonkeyBusiness

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

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on 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
          • CristianMaureiraC Offline
            CristianMaureiraC Offline
            CristianMaureira
            wrote on 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