新蜜蜂在這里堅持了一些簡單的事情。我必須構建一個包含多個影像的大型專案。它們將分層分布在不同的檔案夾中。但是,即使我設定了一個檔案 alias="myimage.qml" 我仍然需要添加完整路徑來正確加載影像。這不是我想要的。換句話說:
這是我的 qml.qrc
<qresource prefix="/View/Images">
<file alias="db_normal.png">View/Images/db_normal.png</file>
<file alias="db_pressed.png">View/Images/db_pressed.png</file>
</qresource>
但是當我嘗試這樣加載資源時:
Image
{
id: buttonId
source: "db_normal.png"
它不起作用,只有當我指定如下完整路徑時:
Image
{
id: buttonId
source: "qrc:/View/Images/db_normal.png"
但這與我想做的事情背道而馳。我將有幾個影像和幾個 QMl 檔案,我不想在所有內容上指定完整路徑。代碼看起來會非常難看。
我總是可以做類似的事情:
屬性字串 rscRoot: "qrc:/View/Images/"
Image
{
id: buttonId
source: rscRoot "qc_normal.png"
但同樣,我不想到處創建路徑變數。有沒有辦法使這項作業:
Image
{
id: buttonId
source: "db_normal.png"
使用檔案別名或其他方法?
謝謝你。
uj5u.com熱心網友回復:
如上所述,您應該擺脫prefix僅使用prefix="/".
<RCC>
<qresource prefix="/">
<file alias="test1">images/test1.jpg</file>
<file>images/test2.jpg</file>
<file>images/test3.jpg</file>
</qresource>
</RCC>
import QtQuick
Window {
width: 800
height: 1000
visible: true
title: qsTr("Hello World")
Column {
Image {
source: "qrc:/test1"
}
Image {
source: "qrc:/images/test2.jpg"
}
Image {
source: "qrc:/images/test3.jpg"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/514825.html
標籤:qtqml
上一篇:大家好,
下一篇:Pyside6回應鍵盤輸入
