QML progress bar is NOT showing up on UI










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...

    – TrebuchetMS
    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...

    – TrebuchetMS
    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









TrebuchetMS

2,90511025




2,90511025










asked Nov 15 '18 at 7:09









user3405291user3405291

1,90711941




1,90711941












  • 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...

    – TrebuchetMS
    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...

    – TrebuchetMS
    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...

– TrebuchetMS
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...

– TrebuchetMS
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.



There are two ways you can accomplish this. You can



  1. Use the item directly.

  2. Save your Qml Progress Bar Item in a separate file, and create an object in an ApplicationWindow.

Lé Code



Method 1



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



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 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)





Then call it from your ApplicationWindow in Main.qml.



// 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;




Make sure that your qml files are in the same directory. If not, place 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/Main.qml, and

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

Then use import "qml" in Main.qml to import the subdirectory/subfolder. Remember, you're importing 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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.



There are two ways you can accomplish this. You can



  1. Use the item directly.

  2. Save your Qml Progress Bar Item in a separate file, and create an object in an ApplicationWindow.

Lé Code



Method 1



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



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 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)





Then call it from your ApplicationWindow in Main.qml.



// 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;




Make sure that your qml files are in the same directory. If not, place 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/Main.qml, and

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

Then use import "qml" in Main.qml to import the subdirectory/subfolder. Remember, you're importing 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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.



There are two ways you can accomplish this. You can



  1. Use the item directly.

  2. Save your Qml Progress Bar Item in a separate file, and create an object in an ApplicationWindow.

Lé Code



Method 1



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



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 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)





Then call it from your ApplicationWindow in Main.qml.



// 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;




Make sure that your qml files are in the same directory. If not, place 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/Main.qml, and

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

Then use import "qml" in Main.qml to import the subdirectory/subfolder. Remember, you're importing 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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.



There are two ways you can accomplish this. You can



  1. Use the item directly.

  2. Save your Qml Progress Bar Item in a separate file, and create an object in an ApplicationWindow.

Lé Code



Method 1



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



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 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)





Then call it from your ApplicationWindow in Main.qml.



// 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;




Make sure that your qml files are in the same directory. If not, place 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/Main.qml, and

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

Then use import "qml" in Main.qml to import the subdirectory/subfolder. Remember, you're importing 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.



There are two ways you can accomplish this. You can



  1. Use the item directly.

  2. Save your Qml Progress Bar Item in a separate file, and create an object in an ApplicationWindow.

Lé Code



Method 1



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



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 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)





Then call it from your ApplicationWindow in Main.qml.



// 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;




Make sure that your qml files are in the same directory. If not, place 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/Main.qml, and

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

Then use import "qml" in Main.qml to import the subdirectory/subfolder. Remember, you're importing 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 Feb 14 at 6:24

























answered Nov 15 '18 at 10:00









TrebuchetMSTrebuchetMS

2,90511025




2,90511025












  • 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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.

    – TrebuchetMS
    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.

– TrebuchetMS
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.

– TrebuchetMS
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.

– TrebuchetMS
Nov 17 '18 at 12:38






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

– TrebuchetMS
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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto