pythonqmlpyqt5qqmlapplicationengine

QML Image not displaying in Application


I am having trouble displaying a simple image into my application. Here's the main.py:

import sys
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtCore import QObject, QUrl


if __name__ == '__main__':
    sys.argv += ['--style', 'material']
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine('basic.qml')
    sys.exit(app.exec_())  

And the basic.qml:

import QtQuick 2.0
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.1

ApplicationWindow {
    visible: true
    width: 200
    height: 400
    title: qsTr("Hello World")
    Material.theme: Material.Light
    Material.accent: Material.Orange
    Column {
        anchors.centerIn: parent
        Button {
            width: 200; height:50;
            font.capitalization: Font.MixedCase
            text: qsTr("Button Name")
            objectName: "button_obj_name"
            highlighted: true
            Material.background: Material.Orange

        }
        Image{
                width: 100; height: 100
                fillMode: Image.PreserveAspectFit
                source: "logo_name.jpg"
            }
    }
}

In the application window it seems that space is allocated but nothing is displaying. [logo_name.jpg is located in the same folder where basic.qml and main.py are in ]


Solution

  • It had something to do with the image I was trying to display(as @Jason R. Mick mentioned),I believe that the image I was trying to use was converted by changing it's extension name.

    As a sanity check can you please post the image you're trying to display & image/listing of folder contents? – Jason R. Mick