Image not loading
Unsolved
Mobile and Embedded
-
Hi,
I am using Qt 6.5.0 and Qt Creator with Ubuntu. I am developing an interface for smart watch. So I was loading a background in it, but it seems not to loadHere is my QML code:
import QtQuick import QtQuick.Window import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 Window { width: 240 height: 240 visible: true color: "transparent" maximumHeight: 240 maximumWidth: 240 minimumHeight: 240 minimumWidth: 240 Rectangle{ id: circular_area height: parent.height width: parent.width radius: parent.width / 2 color: "black" } SwipeView{ id: swipe_view height: parent.height width: parent.width clip: true Item{ id: home_screen Image { id: wallpaper anchors.fill: parent source: "qrc:/images/arcs.png" fillMode: Image.PreserveAspectFit } ColumnLayout{ id: content_layout anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.right: parent.right spacing: 5 Text{ id: time color: "#ffffff" text: "16:00" font.pointSize: 20 font.weight: Font.DemiBold font.family: "Roboto" Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter } Text{ id: day color: "#ffffff" font.weight: Font.ExtraLight font.family: "Robot" Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter } Timer{ interval: 500 running: true repeat: true onTriggered: { var date = new Date() time.text = date.toLocaleTimeString(Qt.locale("en_IN"), "hh:mm") const days = ["Sunday", "Monday", "Tuesday", "Wednessday", "Thursday", "Friday", "Saturday"] let dayIndex = date.getDay() day.text = days[dayIndex] } } } } Item{ } } }
Please help me out
Thanks in advance -
Item{ id: home_screen Image { id: wallpaper anchors.fill: parent source: "qrc:/images/arcs.png" fillMode: Image.PreserveAspectFit }
Your
home_screen
item does not have dimensions (width
andheight
) so in yourImage
the call toanchors.fill: parent
does nothing. So your image is there but it spans 0x0 pixels.Plus, with QRC it's always tricky, so make sure the path is correct and also try other URLs like
:/images/arcs.png
orqrc://images/arcs.png
. -
@Raghav said in Image not loading:
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15import QtQuick.Layouts 1.15 <=version number is dropped in Qt6 import QtQuick.Controls 2.15 <=version number is dropped in Qt6 simply import QtQuick.Layouts import QtQuick.Controls