I have this QML progress bar:
import QtQuick.Controls 2.0 as QQC20
Item {
QQC20.ProgressBar {
id: progressbar_id
visible: false // even if "true", the progress bar does NOT show up on UI
from: editorScene.progressbarMin
to: editorScene.progressbarMax
value: editorScene.progressbarVal
onValueChanged: {
console.log("Progressbar value changed: ", progressbar_id.value)
}
onVisibleChanged: {
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)
}
}
}
I can confirm that the progress bar value and visibility are changed by the methods onValueChanged and onVisibleChanged.
However, the problem is that the progress bar does NOT show up on the UI! How can I actually show the progress bar on the UI? Can anybody give me a hint?
Right now, all you're doing is creating a QML type which you can use as part of your API. To actually see it, you need to create an instance of it under a
ApplicationWindoworWindow(or anything else equivalent, e.g.Canvasor Felgo'sGameWindow).There are two ways you can accomplish this. You can
Lé Code
Method 1: Directly Adding as Child
Directly insert your codeblock as a child of an
ApplicationWindow.Method 2: Using a Separate File
Save your item into a new qml file.
Note that you still need the
importstatements.Then call it from a window in
Main.qml. We'll use anApplicationWindowhere.If your qml files aren't in the same directory, make sure you add an
import "relative/path"at the top of theMain.qmlfile among the other import statements.For example, if
/Users/Lorem/Project,Main.qmlis/Users/Lorem/Project/qml/Main.qml, andMyProgressBar.qmlis/Users/Lorem/Project/qml/myControls/MyProgressBar.qml...Then use
import "myControls"inMain.qmlto import the items from themyControlssubdirectory. Remember, you only need to import the directory, not the file itself.Result
This is what the result resembles when I run it from a macOS.
At startup.
After 3 clicks on the background.
There is also console/debug output after each click: