3
votes

I have my simple PyQt5 application, which includes QML file. I want set Material style for app, but it returns error.

import QtQuick 2.3
import QtQuick.Controls 2.1
import QtQuick.Window 2.2
import QtQuick.Controls.Material 2.1    

ApplicationWindow{
  title: qsTr('Qml app')
  id: mainWindow
  width:  500
  height: 400
  color: '#f6f6f6'
}

How can I fix it? Help me,please My python code is:

import sys
import PyQt5
from PyQt5 import QtWidgets
from PyQt5.QtQuick import QQuickView

if __name__ == '__main__':
     myApp = PyQt5.QtWidgets.QApplication(sys.argv)
     engine = PyQt5.QtQml.QQmlApplicationEngine()
     ctx = engine.rootContext()
     ctx.setContextProperty('main',engine)
     engine.load('styles/mat.qml')
     win = engine.rootObjects()[0]

     win.show()
     sys.exit(myApp.exec_())

And the error message:

Traceback (most recent call last):<br>
  File "C:\My\Python programms\app8.py", line 12, in <module><br>
    win = engine.rootObjects()[0]<br>
IndexError: list index out of range<br>

I am using Python 2.7

1
what is the error message?? - eyllanesc
And what is your python code? - eyllanesc
Edit your post and add your code - eyllanesc
@eyllanesc, yeah, I had a problem with adding my code to comment, so I changed the main question and placed my code in it - Sergey Anisimov
Are you sure the path of the file mat.qml is in a styles folder? - eyllanesc

1 Answers

1
votes

Material Style is available from version 5.7 on Qt.