QML progress bar is NOT showing up on UI
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
add a comment |
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
Item
does not declareimplicitWidth
andimplicitHeight
, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should putanchors.fill: parent
inQQC20.ProgressBar
to make it fill all space the outerItem
gets. Or if possible you could just get rid of the outerItem
– 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
add a comment |
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
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
qt qml progress-bar qtquickcontrols
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 declareimplicitWidth
andimplicitHeight
, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should putanchors.fill: parent
inQQC20.ProgressBar
to make it fill all space the outerItem
gets. Or if possible you could just get rid of the outerItem
– 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
add a comment |
Item
does not declareimplicitWidth
andimplicitHeight
, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should putanchors.fill: parent
inQQC20.ProgressBar
to make it fill all space the outerItem
gets. Or if possible you could just get rid of the outerItem
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
- Use the item directly.
- 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.
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
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 yourMain.qml
or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the fileMySuperAwesomeProgressBar.qml
, useMySuperAwesomeProgressBar 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 myqml.qrc
file:<file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file>
since my file was inside a subdirectory namedqml
– user3405291
Nov 17 '18 at 12:32
1
Ah ok. I thinkimport qml
would've done it as well. But¯_(ツ)_/¯
whatever works for you.
– TrebuchetMS
Nov 17 '18 at 12:38
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
- Use the item directly.
- 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.
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
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 yourMain.qml
or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the fileMySuperAwesomeProgressBar.qml
, useMySuperAwesomeProgressBar 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 myqml.qrc
file:<file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file>
since my file was inside a subdirectory namedqml
– user3405291
Nov 17 '18 at 12:32
1
Ah ok. I thinkimport qml
would've done it as well. But¯_(ツ)_/¯
whatever works for you.
– TrebuchetMS
Nov 17 '18 at 12:38
add a comment |
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
- Use the item directly.
- 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.
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
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 yourMain.qml
or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the fileMySuperAwesomeProgressBar.qml
, useMySuperAwesomeProgressBar 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 myqml.qrc
file:<file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file>
since my file was inside a subdirectory namedqml
– user3405291
Nov 17 '18 at 12:32
1
Ah ok. I thinkimport qml
would've done it as well. But¯_(ツ)_/¯
whatever works for you.
– TrebuchetMS
Nov 17 '18 at 12:38
add a comment |
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
- Use the item directly.
- 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.
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
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
- Use the item directly.
- 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.
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
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 yourMain.qml
or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the fileMySuperAwesomeProgressBar.qml
, useMySuperAwesomeProgressBar 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 myqml.qrc
file:<file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file>
since my file was inside a subdirectory namedqml
– user3405291
Nov 17 '18 at 12:32
1
Ah ok. I thinkimport qml
would've done it as well. But¯_(ツ)_/¯
whatever works for you.
– TrebuchetMS
Nov 17 '18 at 12:38
add a comment |
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 yourMain.qml
or wherever you use it. And make sure you use whatever you name the file with. E.g. if you named the fileMySuperAwesomeProgressBar.qml
, useMySuperAwesomeProgressBar 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 myqml.qrc
file:<file alias="MyProgressBar.qml">qml/MyProgressBar.qml</file>
since my file was inside a subdirectory namedqml
– user3405291
Nov 17 '18 at 12:32
1
Ah ok. I thinkimport 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Item
does not declareimplicitWidth
andimplicitHeight
, so wherever you use your QML file, you must make sure it is given width & height, and on top of that you should putanchors.fill: parent
inQQC20.ProgressBar
to make it fill all space the outerItem
gets. Or if possible you could just get rid of the outerItem
– 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