Drawing rectangle and line using ui.label
-
Hi
i can draw rectangle using QML. For example:*import QtQuick 2.0
Rectangle {
width: 100
height: 100
color: "red"
x: 5
y:10
}*but how i can draw rectangle into Ui ?
using: ui.mylabel.setText("...") i can write
but how i can draw ? rectangle, line … ?thanks
-
What is "ui" you are referring to? Some other QML file? Or qml.ui file? Can you post it's contents?
-
I posted my code here:
https://forum.qt.io/topic/98911/qml-swipeview-and-state-machinethe problem is drawing rectangle in label.
I use: ui->label->setText("ISTRUCTION1 \n"); to write.
But how i can draw ? for example rectangle ?I have to draw rectangle and to write a text.
My code is good for text but not for drawing.
(i have to build a form. My task is similar to this: https://media.istockphoto.com/photos/yes-and-no-boxes-with-red-checkmark-on-no-picture-id185009675 )So I have two choice:
-
drawing rectangle without qml but with method
-
drawing rectangle with qml, for example using this code:
*SwipeView {
id: viewcurrentIndex: 1 anchors.fill: parent Item { id: firstPage } Item { id: secondPage } Item { id: thirdPage }
}
PageIndicator {
id: indicatorcount: view.count currentIndex: view.currentIndex anchors.bottom: view.bottom anchors.horizontalCenter: parent.horizontalCenter
}*
-
-
If you want to add a checkbox, you can do this:
Row { Text { width: contentWindth text: "Some text" } Rectangle { width: 15 height: width border.width: 1 } }
There are many other ways to achieve this, too. There is a built-in CheckBox element, for instance.
-
If you want to add a checkbox, you can do this:
Row { Text { width: contentWindth text: "Some text" } Rectangle { width: 15 height: width border.width: 1 } }
There are many other ways to achieve this, too. There is a built-in CheckBox element, for instance.
@sierdzio no i dont want to add checkbox.
. i want a slide show.
When i push button or combination of buttons, i want ad immagine with text.
for example:
i push esc/enter button and left arrow , i go ahead.
i push esc/enter button esc and right arrow, i go back.
i push button left arrow without button esc or right, nothing must be happened.
i push esc/enter button, i storage i pressed button.
these are my cases.
so i build a state machine.
but i dont connect my state machine in cpp with qml. -
So what that story about drawing a line or a text for? I'm sorry but I can't help you if I don't even know what the question is...
If you want to spawn some QML components based on changes in your state machine, you can use:
- Loader component
- Qt.createComponent
- instantiate custom QQuickItem from C++ and push it to the scene
If you need to learn more abour state transitions, check out https://doc.qt.io/qt-5/qml-tutorial3.html
But I have a feeling that you want something else entirely...
-
thanks for info, i following that.
"So what that story about drawing a line or a text for?"
well, if you see my code, you can see that i show a label with text.
the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...) -
thanks for info, i following that.
"So what that story about drawing a line or a text for?"
well, if you see my code, you can see that i show a label with text.
the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...)@Montanaro said in Drawing rectangle and line using ui.label:
well, if you see my code, you can see that i show a label with text.
I don't have time to research your project. Please paste relevant parts here.
the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...)
That's why I suggested using a CheckBox, that is that it's for. A text element is capable of displaying text, not drawing shapes. You need to change your UI to fit your drawing needs.