How do I amend the text in a Qt Label? - qt

I was wondering how to amend (or more specifically, add) text to a Qt Label, rather than just setting it using setText?

Related

JavaFX Can't set any styles with Text node

I have a text field and I'm able to change the text size of a Text node no problem with
Text text = new Text();
text.setStyle("-fx-font-size: 16;");
but if I try to change the colour, nothing works:
textStart.setStyle("-fx-font-size: 16;-fx-color: #ff0000;-fx-text-base-color: #ff0000;-fx-text-fill: #ff0000;");
I find in JavaFX every node seems to need a different css command to successfully change the colour, but with Text, none of them seem to work. I can change the text with
text.setFill(Color.RED);
But it's awkward to have two separate commands on separate lines when it should be able to be done in one line of css. Especially since what I'm doing is relatively heavy processing of many lines of text.
Does anyone know what the css command to change the colour is with a Text node? Seems so odd it only accepts the size command in css..

How can I set word wrapping in QToolButton's text?

I want to show some text in a QToolButton derived class but it needs to be word wrapped. I would like to do it in an "automatic" way (instead of using \n when needed) just as one can do it when using QLabel and setting word wrapp to true, but I couldn't find anything on Qt Assistant that would do that for me.
So, is it possible? And how is it done? If there is nothing like word wrapping for QToolButton, how could I get around this without using "hard code layout" (that is, \n)?

How to set QLineEdit default text to one space?

I entered one space as a QLineEdit's text in the Qt Creator GUI Designer. I can see that the space is there in the designer wiew, but if I compile and run it, the space disapears. I want this space to be a QLineEdit's default text, how can set it, or tell Qt to do not delete that one space?
My guess is that space disappears because UIs are stored as XML and nodes consisting only of whitespace are strippd (see this question).
But you can set the space to the QLineEdit in the window's constructor:
ui->lineEdit->setText(" ");
If what you want is to have a default text when the widget is empty, use the setPlaceholderText(QString)
If you want to just set a initial value, then do it in the constructor of your app/widget/class with setText(QString)

How to add subscript/superscript to buttons label in flex?

I need to add subscript or superscript and normal text to buttons label. But as far as I understand button's label property is simple label, if it was RichText it would be easy.
I need subscript/superscript + normal text. Also I can't use 2 labels in skin class, I can only have 1 label or 1 RichText in skin class because as far as I understand labelDisplay works only for one label in skin class. Plus my button isn't constant.
So guys any ideas on how to get that done for button?
Here is the solution I found:
Download & install GG Subscript & GG Superscript TrueType fonts. You will need to restart Flash software after installed fonts.
Create a text field with Arial font embeded. Set the HTML property to true.
Create a dynamic text field with GG Subscript font embeded.
Create a dynamic text field with GG Superscript font embeded.
Use htmltext to set text to subscript or superscript like below:
my_txt.text = "Adobe<font face=\"GG Superscript\">TM</font>"
This is old solution for text fields. mx:Label supports htmltext, it may work. I think.

Changing Spark TextArea text color dynamically over a range of characters

Hoping to obtain the help of some Flex 3/4 gurus out there...
I am attempting to dynamically change the color of a subset/portion of text in a Spark TextArea control. Using the MX-based TextArea, I could leverage the mx.controls.textClasses.TextRange type and change the color directly as follows:
TextRange tr = new TextRange(theTextAreaControl, false, beginIndex, endIndex);
tr.color = somePredefindColor;
Input Parameters to TextRange constructor:
1st argument: The TextArea control that will provide access to the underlying textField property
2nd argument: Indicates the TextRange will not modify the content of the TextArea
3rd argument: The beginning index position in the TextArea text string
4th argument: The ending index position in the TextArea text string
How would I go about doing this for a Spark-based TextArea control? I am looking to dynamically change the font color for a range of text, not just the entire TextArea AND I cannot statically specify the font color. The problem I run into when trying to re-use the TextRange type is that the 1st argument is expected to provide the textField property, which is currently not on the Spark-based TextArea control. I thought about extending the Spark-based TextArea control to provide this accessor property but that seems like overkill and is probably not the best approach.
Any help would be greatly appreciated.
Thanks,
Michael
When manipulating Spark text components, you'll want to use the Text Layout Framework (TLF), which is built on top of the Flash Text Engine (FTE) that was introduced in Flash Player 10. It gives you major control over how the text is displayed (at the cost of being pretty complex.) Here's a good place to start: Using Text Layout Framework

Resources