I want to design 3 dots in qml using Text and Rectangle as shown below;
... Hello World ...
But my requirement is 3 dots should lie at the middle of the rectangle and the text (Hello World) as shown in the image. How this can be achieved?
When I thought first time, 2 approaches came up in my mind:
1- Using the middle dot by the help of html code styles can achieve this. Here is the HTML codes which you can easiy use in qml.
Here is the example and output:
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle{
id:sample1
anchors.centerIn: parent
width: 200
height: 50
border.color: "black"
Text {
id: mytext
anchors.centerIn: parent
textFormat: Text.RichText
text: "·" + "·" + "·" + " Hello World " + "·" + "·" + "·"
}
}
}
Output:
2- You can put the "Hello world" text first then you can create another text for dots and put the dots in the mid coordinates beside the main text. This method is not a beautiful approach.
Note: When I dig into to other possible solutions, I couldn't see a proper solution to achieve this.
Related
I'm learning how to make Plasmoids with QML, and I'm using Plasmoidviewer to view the package as I build it.
However, when I launch it, my widget is clipped into the lower right corner, like this:
If I resize the window a bit, then resize it back to the original size, the widget snaps into view:
The main.qml is just a simple Hello World:
Item {
//Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
Plasmoid.fullRepresentation: Rectangle {
color: "blue"
opacity: 0.3
Layout.minimumWidth: label.implicitWidth
Layout.minimumHeight: label.implicitHeight
Layout.preferredWidth: 640 * PlasmaCore.Units.devicePixelRatio
Layout.preferredHeight: 480 * PlasmaCore.Units.devicePixelRatio
PlasmaComponents.Label {
id: label
anchors.fill: parent
text: "Hello World!"
horizontalAlignment: Text.AlignHCenter
}
}
}
Any idea why this is happening, and how I can get the widget to be displayed in the center of plasmoidviewer? This is really annoying to develop with.
I'm making a vehicle's instrument cluster in QML and wanted to align the speed labels to the curve in such a way that they are all the same distance away from it. To do this, I used pathview to set up an arc, then used the text delegate to have the text appear in the right places. The reason it's not working exactly as intended is that some text is larger than other (for example '0' takes less space than '100') which causes some variability in distance between the text and the circle I'm trying to align it with. How can this be done better?
Here's the snippet of what I have got working so far:
Component {
id: spdLabel
Text {
font.weight: Font.Normal
font.pixelSize: 28
color: "white"
text: model.index
visible: model.index % spdMarkInterval == 0
}
}
PathView {
anchors.fill: parent
z: 0
model: topSpeed + 1
delegate: spdLabel
path: Path {
PathAngleArc {
centerX: (dialGauge.x + dialGauge.width)/2
centerY: (dialGauge.y + dialGauge.height)/2
radiusX: 140
radiusY: 140
sweepAngle: 270
startAngle: 135
}
}
}
Here's what the result looks like:
Since it is the center of text elements that's anchored a constant distance away from the arc, the distance between the text edge and arc varies.
Thanks for any help!
I've got 3 basic elements in a rectangle and I'd like to draw line separations between them.
I don't find an easy way to achieve that, as a border-left would do in CSS.
Text {
id : txtNote
text : (__notes.length>0)?__notes[0].extname.name:"--"
anchors.right: txtNoteAcc.left
leftPadding: 5
rightPadding: 0
}
Image {
id : txtNoteAcc
height : 20
width : 20
anchors.right: txtNoteHead.left
}
Image {
id : txtNoteHead
height : 20
width : 20
anchors.right: parent.right
}
Now laid out as:
And the goal is to have it a similar way (this example is a Java one):
I've found this approach, but I don't call it "simple" and it is 7 years old.
Rem: I'm working with QML 5.9 (so Shape is not available).
I am looking for a way to show a text hint stating the expected input as advice for the user. Take the Google search bar for example:
Is there a property I am missing, or is this something that has to be achieved through scripting?
The property doesn't exist on the Qt Quick input items. You can vote for the feature here.
In the meantime, you can use TextArea from Qt Quick Controls 2.
If you would rather use pure Qt Quick, you can do something similar to what the Controls do and add a Text item above the field:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
width: 300
height: 300
visible: true
TextEdit {
id: textEdit
width: 200
height: 50
property string placeholderText: "Enter text here..."
Text {
text: textEdit.placeholderText
color: "#aaa"
visible: !textEdit.text
}
}
}
This is kinda old but I found another necessity for Android builds.
Since Android only send the text editing signal after you press ok in virtual keyboard, the placeholder remains there. So to avoid it, I recommend:
TextEdit {
id: textEdit
width: 200
height: 50
property string placeholderText: "Enter text here..."
Text {
text: textEdit.placeholderText
color: "#aaa"
visible: !textEdit.text && !textEdit.activeFocus // <----------- ;-)
}
}
If you want one line input then why not use TextField ?
I have a Rectangle and on top of it there is a Text item. Text contained in the latter does exceeding its boundary.
Here is my code:
Rectangle{
width: 100
height: 100
anchors.centerIn: parent
color: "lightblue"
Text{
width: parent.width
height: parent.height
text: "hi hello how are you. good how do you dosdfskdjgbksajgsjdfsjadfsad \n"+
"sdfvbjsdkfjsbdvfsd sjkdbfvskdbfvskdbvs,dv jskbdvksdbvasd \n"+
"sajbfwkbedcv klanfuoigbefhbsdaf csa djsdagfbksdjbfvsadkjvABEGFW\n"+
"JGBGFWJAHGRJWEKHYJGWKGBFWHE gofdgfdfgdf"
wrapMode: Text.WordWrap
fontSizeMode: Text.Fit
}
}
It's documented:
Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, contentWidth will exceed a set width.
That's what's happening with your text. You probably want to use Text.Wrap:
Text.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word.
Combined with some eliding, the text will fit perfectly within the Rectangle:
elide: Text.ElideRight