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. Converting c++ into Python
Forum Updated to NodeBB v4.3 + New Features

Converting c++ into Python

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 644 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.
  • P Offline
    P Offline
    Pythonic person
    wrote on 1 Dec 2023, 20:50 last edited by
    #1

    Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
    unity thread
    GitHub Code of C++ working example

    So can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.

    B C 2 Replies Last reply 2 Dec 2023, 05:04
    0
    • P Pythonic person
      1 Dec 2023, 20:50

      Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
      unity thread
      GitHub Code of C++ working example

      So can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.

      B Offline
      B Offline
      BamboozledBaboon
      wrote on 2 Dec 2023, 05:04 last edited by BamboozledBaboon 12 Feb 2023, 05:05
      #2

      @Pythonic-person
      I don't know what this unity thing is so I don't know what this is supposed to do. I converted over most of it but I left out the windows OS specific stuff because I didn't feel like messing with it at the moment (I don't know much c++ either). It's pyside6 instead of pyqt5 but hopefully this will be enough to get you started.

      import sys
      from PySide6.QtCore import Qt
      from PySide6.QtWidgets import QApplication, QMainWindow, QSplitter, QWidget
      from PySide6.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsTextItem, QGraphicsItem
      from PySide6.QtGui import QPainter
      
      from PySide6.QtCore import QProcess
      
      
      class UnityWindow(QWidget):
          def __init__(self, unityExePath, parent=None):
              super().__init__(parent)
              self._m_unityHandle = 0
              self._m_bIsValid = False
              self._m_pUnityProcess = None
              self._m_unityExecutablePath = unityExePath
              app.applicationStateChanged.connect(self.applicationStateChanged)
      
          def enumChildWindows(self, handle):
              # if windows do stuff
              pass
      
          def isValid(self):
              return self._m_bIsValid
      
          def applicationStateChanged(self, state):
              # if windows do stuff
              pass
      
          def resizeEvent(self, ev):
              super().resizeEvent(ev)
              # if windows do stuff
      
          def sEnumChildWindows(self, handle, params):
              # if windows do stuff
              pass
      
          def showEvent(self, ev):
              super().showEvent(ev)
              # if windows do stuff
      
          def hideEvent(self, ev):
              super().hideEvent(ev)
              # if windows do stuff
      
          def nativeEvent(self, eventType, message, result):
              # if windows do stuff
              return QWidget.nativeEvent(eventType, message, result)
      
      
      if __name__ == '__main__':
          app = QApplication(sys.argv)
      
          mainWindow = QMainWindow()
      
          splitter = QSplitter(mainWindow)
          splitter.setOrientation(Qt.Horizontal)
      
          unityWindow = UnityWindow("unity-game.exe", mainWindow)
          splitter.addWidget(unityWindow)
      
          view = QGraphicsView(mainWindow)
          scene = QGraphicsScene(mainWindow)
      
          item = QGraphicsTextItem("Test Item")
          item.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable)
          scene.addItem(item)
      
          view.setRenderHint(QPainter.Antialiasing, False)
          view.setDragMode(QGraphicsView.ScrollHandDrag)
          view.setInteractive(True)
          view.setOptimizationFlags(QGraphicsView.DontSavePainterState)
          view.setViewportUpdateMode(QGraphicsView.SmartViewportUpdate)
          view.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
          view.setScene(scene)
      
          splitter.addWidget(view)
      
          mainWindow.setCentralWidget(splitter)
      
          mainWindow.show()
      
          sys.exit(app.exec())
      
      1 Reply Last reply
      0
      • P Pythonic person
        1 Dec 2023, 20:50

        Hello all, and am super sorry to post such a thing but am super noob with C++ language and I was struggling with the integration external application within my pyqt5 app but am stuck with many problem and they are addressed here in this link:
        unity thread
        GitHub Code of C++ working example

        So can any body help me with converting that code from git into a working python. and again am super sorry for my dumb question.

        C Offline
        C Offline
        CristianMaureira
        wrote on 4 Dec 2023, 22:44 last edited by
        #3

        Hello @Pythonic-person
        In the Qt for Python repository, we have an internal tool that's for sure not ready for production, but it help us to transform some C++ code to Python:

        https://code.qt.io/cgit/pyside/pyside-setup.git/tree/tools/qtcpp2py.py

        I hope it helps with future projects :)

        1 Reply Last reply
        1

        1/3

        1 Dec 2023, 20:50

        • Login

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