我无法在我的应用程序中显示一个简单的图像。这是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_())
和 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"
}
}
}
在应用程序窗口中,似乎分配了空间,但没有显示任何内容。[logo_name.jpg 位于 basic.qml 和 main.py 所在的同一文件夹]