[PyQt] Problem with QQmlApplicationEngine

Charlie Gentil ceg at redaction-developpez.com
Wed Nov 27 07:07:01 GMT 2013


Hello,

I write a program PyQt5.1 and Qt Quick. I wish I could use MenuBar and I try to 
use QQmlApplicationEngine.

When I run my Python script a white window appears without the MenuBar, but I 
have no default.

Here are my codes:

*_test.py_*
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtCore import QObject, QUrl, QSize
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView, QQuickWindow
from PyQt5.QtQml import qmlRegisterType, QQmlApplicationEngine



class MainClass(QObject):
    def /__init__/(self, parent=None):
        super(MainClass, self)./__init__/(parent)

qmlRegisterType(MainClass, "Charts", 1, 0, "MainClass")

app = QApplication(sys.argv)
engine = QQmlApplicationEngine('test.qml')
topLevel=  engine.rootObjects()[0]
win = QQuickWindow(topLevel)
win.show()
sys.exit(app.exec_())



*_test.qml_*
import QtQuick 2.1
import QtQuick.Controls 1.0

ApplicationWindow {
    id: /application/

    menuBar : MenuBar {
        Menu {
            title: "File"
            MenuItem { text: "Open..." }
            MenuItem { text: "Close" }
        }

        Menu {
            title: "Edit"
            MenuItem { text: "Cut" }
            MenuItem { text: "Copy" }
            MenuItem { text: "Paste" }
        }
    }


}


Can you help me.

In advance thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131127/abbd071b/attachment-0001.html>


More information about the PyQt mailing list