Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QML to Python

QML to Python

Scheduled Pinned Locked Moved Unsolved Language Bindings
2 Posts 2 Posters 2.3k 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.
  • N Offline
    N Offline
    Nathan Miguel
    wrote on last edited by
    #1

    I followed more than multi tutorials teaching this but it does not work at all, I use python 3.7 and I want to know how to convert a qml file to a gui in python. If you have how to convert xml to gui in python tell me too.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      There's nothing to convert.

      main.py:

      #!/usr/bin/env python
      
      import sys
      
      from os.path import join
      from os.path import dirname
      
      from PyQt5.QtCore import QUrl
      from PyQt5.QtGui import QGuiApplication
      from PyQt5.QtQuick import QQuickView
      
      
      if __name__ == "__main__":
      
          app = QGuiApplication(sys.argv)
      
          url = QUrl(join(dirname(__file__), 'main.qml'))
      
          view = QQuickView()
          view.setSource(url)
          view.show()
      
          sys.exit(app.exec_())
      

      main.qml:

      import QtQuick 2.0
      
      Rectangle {
          width: 360
          height: 360
      
          Text {
              text: qsTr("Hello Qt")
              anchors.centerIn: parent
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  Qt.quit()
              }
          }
      }
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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