QML progress bar is NOT showing up on UI



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















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?










share|improve this question
























  • Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

    – Amfasis
    Nov 15 '18 at 9:41






  • 1





    @Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

    – TrebledJ
    Nov 15 '18 at 10:04


















1















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?










share|improve this question
























  • Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

    – Amfasis
    Nov 15 '18 at 9:41






  • 1





    @Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

    – TrebledJ
    Nov 15 '18 at 10:04














1












1








1








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?










share|improve this question
















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?







qt qml progress-bar qtquickcontrols






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 10:24









TrebledJ

3,50621228




3,50621228










asked Nov 15 '18 at 7:09









user3405291user3405291

1,93912141




1,93912141












  • Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

    – Amfasis
    Nov 15 '18 at 9:41






  • 1





    @Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

    – TrebledJ
    Nov 15 '18 at 10:04


















  • Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

    – Amfasis
    Nov 15 '18 at 9:41






  • 1





    @Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

    – TrebledJ
    Nov 15 '18 at 10:04

















Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

– Amfasis
Nov 15 '18 at 9:41





Item does not declare implicitWidth and implicitHeight, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should put anchors.fill: parent in QQC20.ProgressBar to make it fill all space the outer Item gets. Or if possible you could just get rid of the outer Item

– Amfasis
Nov 15 '18 at 9:41




1




1





@Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

– TrebledJ
Nov 15 '18 at 10:04






@Amfasis I'm not finding that to be an error... For me, ProgressBar automatically sets a width and height. I'm on a MacOS, not sure if that changes anything...

– TrebledJ
Nov 15 '18 at 10:04













1 Answer
1






active

oldest

votes


















4














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 ApplicationWindow or Window (or anything else equivalent, e.g. Canvas or Felgo's GameWindow).



There are two ways you can accomplish this. You can



  1. Directly add your item as a child of a window.

  2. Put your item in a separate file, and create an instance of that file under a window.

Lé Code



Method 1: Directly Adding as Child



Directly insert your codeblock as a child of an ApplicationWindow.



// Main.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Window 2.0 // for `ApplicationWindow`
import QtQuick.Controls 2.0 // as QQC20 // no need to label a namespace unless disambiguation is necessary

ApplicationWindow

width: 480 // set the dimensions of the application window
height: 320

// here's your item
Item
anchors.centerIn: parent // place in centre of window

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // horizontally align the progress bar

from: 0 // don't know what editorScene is
to: 100 // so I'm using raw values
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
// side note: I'm not getting any output from this handler
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)




// provide user-interaction for changing progress bar's value
MouseArea
anchors.fill: parent // clicking anywhere on the background
onClicked: progressbar_id.value += 5; // increments the progress bar
// and triggers onValueChanged




Method 2: Using a Separate File



Save your item into a new qml file.



// MyProgressBar.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Controls 2.0 // for `ProgressBar`

// here is your item, it has grown up to be in a file of its own 🚼
Item

property alias value: progressbar_id.value // for user-interaction

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // centre horizontally

from: 0
to: 100
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)





Note that you still need the import statements.



Then call it from a window in Main.qml. We'll use an ApplicationWindow here.



// Main.qml
import QtQuick 2.0
import QtQuick.Window 2.0 // for `ApplicationWindow`

// import "relative/path/to/progressbar" // use this if MyProgressBar.qml is not in the same folder as Main.qml

ApplicationWindow

width: 480
height: 320

MyProgressBar
id: progressbar_id


MouseArea
anchors.fill: parent
onClicked: progressbar_id.value += 5;




If your qml files aren't in the same directory, make sure you add an import "relative/path" at the top of the Main.qml file among the other import statements.



For example, if



  • Your Qml project is in /Users/Lorem/Project,

  • The full path to your Main.qml is /Users/Lorem/Project/qml/Main.qml, and

  • The full path to your MyProgressBar.qml is /Users/Lorem/Project/qml/myControls/MyProgressBar.qml...

Then use import "myControls" in Main.qml to import the items from the myControls subdirectory. 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.



At startup.



After 3 clicks on the background.



After 3 clicks on the background.



There is also console/debug output after each click:



Progressbar value changed: 10
Progressbar value changed: 15
Progressbar value changed: 20





share|improve this answer

























  • When implementing method 2, I receive an error saying: MyProgressBar is not a type

    – user3405291
    Nov 17 '18 at 12:19











  • Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

    – TrebledJ
    Nov 17 '18 at 12:21







  • 1





    Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

    – user3405291
    Nov 17 '18 at 12:32







  • 1





    Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

    – TrebledJ
    Nov 17 '18 at 12:38












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314110%2fqml-progress-bar-is-not-showing-up-on-ui%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














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 ApplicationWindow or Window (or anything else equivalent, e.g. Canvas or Felgo's GameWindow).



There are two ways you can accomplish this. You can



  1. Directly add your item as a child of a window.

  2. Put your item in a separate file, and create an instance of that file under a window.

Lé Code



Method 1: Directly Adding as Child



Directly insert your codeblock as a child of an ApplicationWindow.



// Main.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Window 2.0 // for `ApplicationWindow`
import QtQuick.Controls 2.0 // as QQC20 // no need to label a namespace unless disambiguation is necessary

ApplicationWindow

width: 480 // set the dimensions of the application window
height: 320

// here's your item
Item
anchors.centerIn: parent // place in centre of window

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // horizontally align the progress bar

from: 0 // don't know what editorScene is
to: 100 // so I'm using raw values
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
// side note: I'm not getting any output from this handler
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)




// provide user-interaction for changing progress bar's value
MouseArea
anchors.fill: parent // clicking anywhere on the background
onClicked: progressbar_id.value += 5; // increments the progress bar
// and triggers onValueChanged




Method 2: Using a Separate File



Save your item into a new qml file.



// MyProgressBar.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Controls 2.0 // for `ProgressBar`

// here is your item, it has grown up to be in a file of its own 🚼
Item

property alias value: progressbar_id.value // for user-interaction

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // centre horizontally

from: 0
to: 100
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)





Note that you still need the import statements.



Then call it from a window in Main.qml. We'll use an ApplicationWindow here.



// Main.qml
import QtQuick 2.0
import QtQuick.Window 2.0 // for `ApplicationWindow`

// import "relative/path/to/progressbar" // use this if MyProgressBar.qml is not in the same folder as Main.qml

ApplicationWindow

width: 480
height: 320

MyProgressBar
id: progressbar_id


MouseArea
anchors.fill: parent
onClicked: progressbar_id.value += 5;




If your qml files aren't in the same directory, make sure you add an import "relative/path" at the top of the Main.qml file among the other import statements.



For example, if



  • Your Qml project is in /Users/Lorem/Project,

  • The full path to your Main.qml is /Users/Lorem/Project/qml/Main.qml, and

  • The full path to your MyProgressBar.qml is /Users/Lorem/Project/qml/myControls/MyProgressBar.qml...

Then use import "myControls" in Main.qml to import the items from the myControls subdirectory. 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.



At startup.



After 3 clicks on the background.



After 3 clicks on the background.



There is also console/debug output after each click:



Progressbar value changed: 10
Progressbar value changed: 15
Progressbar value changed: 20





share|improve this answer

























  • When implementing method 2, I receive an error saying: MyProgressBar is not a type

    – user3405291
    Nov 17 '18 at 12:19











  • Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

    – TrebledJ
    Nov 17 '18 at 12:21







  • 1





    Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

    – user3405291
    Nov 17 '18 at 12:32







  • 1





    Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

    – TrebledJ
    Nov 17 '18 at 12:38
















4














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 ApplicationWindow or Window (or anything else equivalent, e.g. Canvas or Felgo's GameWindow).



There are two ways you can accomplish this. You can



  1. Directly add your item as a child of a window.

  2. Put your item in a separate file, and create an instance of that file under a window.

Lé Code



Method 1: Directly Adding as Child



Directly insert your codeblock as a child of an ApplicationWindow.



// Main.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Window 2.0 // for `ApplicationWindow`
import QtQuick.Controls 2.0 // as QQC20 // no need to label a namespace unless disambiguation is necessary

ApplicationWindow

width: 480 // set the dimensions of the application window
height: 320

// here's your item
Item
anchors.centerIn: parent // place in centre of window

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // horizontally align the progress bar

from: 0 // don't know what editorScene is
to: 100 // so I'm using raw values
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
// side note: I'm not getting any output from this handler
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)




// provide user-interaction for changing progress bar's value
MouseArea
anchors.fill: parent // clicking anywhere on the background
onClicked: progressbar_id.value += 5; // increments the progress bar
// and triggers onValueChanged




Method 2: Using a Separate File



Save your item into a new qml file.



// MyProgressBar.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Controls 2.0 // for `ProgressBar`

// here is your item, it has grown up to be in a file of its own 🚼
Item

property alias value: progressbar_id.value // for user-interaction

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // centre horizontally

from: 0
to: 100
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)





Note that you still need the import statements.



Then call it from a window in Main.qml. We'll use an ApplicationWindow here.



// Main.qml
import QtQuick 2.0
import QtQuick.Window 2.0 // for `ApplicationWindow`

// import "relative/path/to/progressbar" // use this if MyProgressBar.qml is not in the same folder as Main.qml

ApplicationWindow

width: 480
height: 320

MyProgressBar
id: progressbar_id


MouseArea
anchors.fill: parent
onClicked: progressbar_id.value += 5;




If your qml files aren't in the same directory, make sure you add an import "relative/path" at the top of the Main.qml file among the other import statements.



For example, if



  • Your Qml project is in /Users/Lorem/Project,

  • The full path to your Main.qml is /Users/Lorem/Project/qml/Main.qml, and

  • The full path to your MyProgressBar.qml is /Users/Lorem/Project/qml/myControls/MyProgressBar.qml...

Then use import "myControls" in Main.qml to import the items from the myControls subdirectory. 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.



At startup.



After 3 clicks on the background.



After 3 clicks on the background.



There is also console/debug output after each click:



Progressbar value changed: 10
Progressbar value changed: 15
Progressbar value changed: 20





share|improve this answer

























  • When implementing method 2, I receive an error saying: MyProgressBar is not a type

    – user3405291
    Nov 17 '18 at 12:19











  • Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

    – TrebledJ
    Nov 17 '18 at 12:21







  • 1





    Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

    – user3405291
    Nov 17 '18 at 12:32







  • 1





    Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

    – TrebledJ
    Nov 17 '18 at 12:38














4












4








4







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 ApplicationWindow or Window (or anything else equivalent, e.g. Canvas or Felgo's GameWindow).



There are two ways you can accomplish this. You can



  1. Directly add your item as a child of a window.

  2. Put your item in a separate file, and create an instance of that file under a window.

Lé Code



Method 1: Directly Adding as Child



Directly insert your codeblock as a child of an ApplicationWindow.



// Main.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Window 2.0 // for `ApplicationWindow`
import QtQuick.Controls 2.0 // as QQC20 // no need to label a namespace unless disambiguation is necessary

ApplicationWindow

width: 480 // set the dimensions of the application window
height: 320

// here's your item
Item
anchors.centerIn: parent // place in centre of window

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // horizontally align the progress bar

from: 0 // don't know what editorScene is
to: 100 // so I'm using raw values
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
// side note: I'm not getting any output from this handler
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)




// provide user-interaction for changing progress bar's value
MouseArea
anchors.fill: parent // clicking anywhere on the background
onClicked: progressbar_id.value += 5; // increments the progress bar
// and triggers onValueChanged




Method 2: Using a Separate File



Save your item into a new qml file.



// MyProgressBar.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Controls 2.0 // for `ProgressBar`

// here is your item, it has grown up to be in a file of its own 🚼
Item

property alias value: progressbar_id.value // for user-interaction

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // centre horizontally

from: 0
to: 100
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)





Note that you still need the import statements.



Then call it from a window in Main.qml. We'll use an ApplicationWindow here.



// Main.qml
import QtQuick 2.0
import QtQuick.Window 2.0 // for `ApplicationWindow`

// import "relative/path/to/progressbar" // use this if MyProgressBar.qml is not in the same folder as Main.qml

ApplicationWindow

width: 480
height: 320

MyProgressBar
id: progressbar_id


MouseArea
anchors.fill: parent
onClicked: progressbar_id.value += 5;




If your qml files aren't in the same directory, make sure you add an import "relative/path" at the top of the Main.qml file among the other import statements.



For example, if



  • Your Qml project is in /Users/Lorem/Project,

  • The full path to your Main.qml is /Users/Lorem/Project/qml/Main.qml, and

  • The full path to your MyProgressBar.qml is /Users/Lorem/Project/qml/myControls/MyProgressBar.qml...

Then use import "myControls" in Main.qml to import the items from the myControls subdirectory. 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.



At startup.



After 3 clicks on the background.



After 3 clicks on the background.



There is also console/debug output after each click:



Progressbar value changed: 10
Progressbar value changed: 15
Progressbar value changed: 20





share|improve this answer















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 ApplicationWindow or Window (or anything else equivalent, e.g. Canvas or Felgo's GameWindow).



There are two ways you can accomplish this. You can



  1. Directly add your item as a child of a window.

  2. Put your item in a separate file, and create an instance of that file under a window.

Lé Code



Method 1: Directly Adding as Child



Directly insert your codeblock as a child of an ApplicationWindow.



// Main.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Window 2.0 // for `ApplicationWindow`
import QtQuick.Controls 2.0 // as QQC20 // no need to label a namespace unless disambiguation is necessary

ApplicationWindow

width: 480 // set the dimensions of the application window
height: 320

// here's your item
Item
anchors.centerIn: parent // place in centre of window

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // horizontally align the progress bar

from: 0 // don't know what editorScene is
to: 100 // so I'm using raw values
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
// side note: I'm not getting any output from this handler
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)




// provide user-interaction for changing progress bar's value
MouseArea
anchors.fill: parent // clicking anywhere on the background
onClicked: progressbar_id.value += 5; // increments the progress bar
// and triggers onValueChanged




Method 2: Using a Separate File



Save your item into a new qml file.



// MyProgressBar.qml
import QtQuick 2.0 // for `Item`
import QtQuick.Controls 2.0 // for `ProgressBar`

// here is your item, it has grown up to be in a file of its own 🚼
Item

property alias value: progressbar_id.value // for user-interaction

ProgressBar
id: progressbar_id

anchors.horizontalCenter: parent.horizontalCenter // centre horizontally

from: 0
to: 100
value: 5

onValueChanged:
console.log("Progressbar value changed: ", progressbar_id.value)

onVisibleChanged:
console.log("Progressbar visibility chanaged: ", progressbar_id.visible)





Note that you still need the import statements.



Then call it from a window in Main.qml. We'll use an ApplicationWindow here.



// Main.qml
import QtQuick 2.0
import QtQuick.Window 2.0 // for `ApplicationWindow`

// import "relative/path/to/progressbar" // use this if MyProgressBar.qml is not in the same folder as Main.qml

ApplicationWindow

width: 480
height: 320

MyProgressBar
id: progressbar_id


MouseArea
anchors.fill: parent
onClicked: progressbar_id.value += 5;




If your qml files aren't in the same directory, make sure you add an import "relative/path" at the top of the Main.qml file among the other import statements.



For example, if



  • Your Qml project is in /Users/Lorem/Project,

  • The full path to your Main.qml is /Users/Lorem/Project/qml/Main.qml, and

  • The full path to your MyProgressBar.qml is /Users/Lorem/Project/qml/myControls/MyProgressBar.qml...

Then use import "myControls" in Main.qml to import the items from the myControls subdirectory. 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.



At startup.



After 3 clicks on the background.



After 3 clicks on the background.



There is also console/debug output after each click:



Progressbar value changed: 10
Progressbar value changed: 15
Progressbar value changed: 20






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 15 at 10:58

























answered Nov 15 '18 at 10:00









TrebledJTrebledJ

3,50621228




3,50621228












  • When implementing method 2, I receive an error saying: MyProgressBar is not a type

    – user3405291
    Nov 17 '18 at 12:19











  • Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

    – TrebledJ
    Nov 17 '18 at 12:21







  • 1





    Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

    – user3405291
    Nov 17 '18 at 12:32







  • 1





    Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

    – TrebledJ
    Nov 17 '18 at 12:38


















  • When implementing method 2, I receive an error saying: MyProgressBar is not a type

    – user3405291
    Nov 17 '18 at 12:19











  • Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

    – TrebledJ
    Nov 17 '18 at 12:21







  • 1





    Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

    – user3405291
    Nov 17 '18 at 12:32







  • 1





    Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

    – TrebledJ
    Nov 17 '18 at 12:38

















When implementing method 2, I receive an error saying: MyProgressBar is not a type

– user3405291
Nov 17 '18 at 12:19





When implementing method 2, I receive an error saying: MyProgressBar is not a type

– user3405291
Nov 17 '18 at 12:19













Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

– TrebledJ
Nov 17 '18 at 12:21






Are they in the same folder? If not, remember to import the folder in your Main.qml or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the file MySuperAwesomeProgressBar.qml, use MySuperAwesomeProgressBar id: progress_bar . Other than that, I can't guess what's causing your error.

– TrebledJ
Nov 17 '18 at 12:21





1




1





Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

– user3405291
Nov 17 '18 at 12:32






Thanks! It got resolved. I just had to add this statement to my qml.qrc file: <file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file> since my file was inside a subdirectory named qml

– user3405291
Nov 17 '18 at 12:32





1




1





Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

– TrebledJ
Nov 17 '18 at 12:38






Ah ok. I think import qml would've done it as well. But ¯_(ツ)_/¯ whatever works for you.

– TrebledJ
Nov 17 '18 at 12:38




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314110%2fqml-progress-bar-is-not-showing-up-on-ui%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo