JavaFX Dynamic label text - javafx

How can I bind seconds to a property to make a label display text like "Left X seconds..."
label.textProperty().bind(secondsProperty)
just replaces whole text of the label to seconds.

You can do something like
label.textProperty().bind(Bindings.format("%s seconds left", secondsProperty));
You didn't specify the type of secondsProperty, but if it is a DoubleProperty (or other NumberExpression) you could also do
label.textProperty().bind(secondsProperty.asString("%f seconds left"));

Related

QLabel setText not displaying text of QLineEdit if label size small

I have a QLabel in which I want to show text from a QLineEdit. The size of line-edit is bigger than the label so I want to show the label ending with a dotted line
ui->LE_Serverpath// contains 20 charecters
ui->LB_UsernameInfo // having size of 10 charecters
ui->LB_UsernameInfo->setText(ui->LE_Serverpath->text());
using wordwrap the line is getting cut but I need dotted lines at the end
ui->LB_UsernameInfo->setWordWrap(true);
You have to set an ElideMode for the label, you need a QFontMetrics instance from label font then set text elide mode for the label. to show dots by end of line, set ElidMode to Qt::ElideRight, on the text copied form QLieEdit:
//QFontMetrics metrics(ui->LB_UsernameInfo->font()); // QLabel already has font metrics
int width = ui->LB_UsernameInfo->width() - 2;
QString text = ui->LB_UsernameInfo->fontMetrics().elidedText(ui->LE_Serverpath->text(), Qt::ElideRight, width);
ui->LB_UsernameInfo->setText(text);
ui->LB_UsernameInfo->setWordWrap(true);
use Qt's layout classes, it will take care of the resizing according to text width.

how to display part of text in qcombobox (QT)

My understanding is the current display text is related to the qcombobox itemlist content.If one item length is very long and wider than qcombobox's width.how to just display part of the text on the qcombobox?
seen from the above picture, QT already displays part of the text(the full item is ending with 'ker', the display item is ending with 'sdl') but can I control the exact display text? because my combobox has a background image and the arrow will be more left than the that in the above picture .
Another question is can I control the item text display in dropdown window as well? QT replaces some words with '...' but I like to control it myself.
try this
m_combobox->addItem("a very long long long long long long text ");
QFont font("times", 24);
QFontMetrics fm(font);
QString elidedText= fm.elidedText("a very long long long long long long text ",Qt::ElideRight, 80);
m_combobox->addItem(elidedText);
you can make a function that takes a QString as parameter and return a QString you give it your text and it return the elided text.
you can store an arbitrary substring as items text and the whole string in userData:
in pyqt:
for text in itemlist:
combobox.addItem(text[0:n], text)
and get the displaytext, userData by:
combobox.currentText()
combobox.currentData(QtCore.Qt.UserRole)
or by
combobox.itemText(index)
combobox.itemData(index, QtCore.Qt.UserRole)

How can I programmatically get text selection in Adobe After Effects with ExtendScripts

I have object TextLayer with white text color string. Then I animate text color selection (second character changes color white -> blue).
How can I get this selection and color programmatically?
Seems like you can't reach the selection start and end values by scripting. But you can add expression controller effect and get the values from that one.
The code below asumes you have one comp in your project with an text layer called "my text layer".
Add an expression controller for color to that layer. Add the expression text.animator("Animator 1").property.fillColor to that effect.
You can do the same thing with the values from your selection.
var preExpression = true;
var currentTime = 5; // in seconds
// get the sourceText? works!
var val = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Document").valueAtTime(currentTime, preExpression);
// get the Text Percent Start? Wont work!
var sel = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Animators").property("ADBE Text Animator").property("ADBE Text Selectors").property("ADBE Text Selector").property("ADBE Text Percent Start").valueAtTime(currentTime, preExpression);
// add an expression controller for color and get the color from that one? works!
var col = app.project.item(1).layer("my text layer").property("ADBE Effect Parade").property("ADBE Color Control").property("ADBE Color Control-0001").valueAtTime(currentTime, false);
$.writeln(val);
$.writeln(sel);
$.writeln(col);
Take a look into the After Effects Scripting Guide. Use redefinery's rd_GimmePropPath script to get the match names of properties.

Restricting the OptionGroup width in Vaadin

I have a couple of OptionGroups with very long captions that run across the width of the page, which looks very bad. I tried restricting the width of the OptionGroup using setWidth and via CSS, and also tried restricting the width of the parent container; all without effect.
So I made a grid layout with an option group in the first column (spanning all rows), and individual labels for the captions in the second column (one per row). However, in case the captions span multiple lines (which they do in my case), this leads to the radio buttons / checkboxes no longer being aligned to the captions. (Regrettably, I'm not allowed to post images.) For instance,
(o) This is a multiline
(o) caption
This is another multiline
caption
I resolved this by creating one OptionGroup per label, and adding each option group in the first column:
(o) This is a multiline
caption
(o) This is another multiline
caption
Clearly, in case of radio buttons, this means multiple buttons can be selected at the same time, since they are no longer linked via a single OptionGroup. Therefore, I registered listeners which, each time a button is selected, de-select all other buttons. And this brings me to my problem; since this "unchecking" is done at the server side, there will unavoidably be some lag, meaning that for some time, multiple radio buttons will appear selected at the client side.
Any ideas on how to resolve this? I only started working with Vaadin recently, so I'm far from an expert. Is there some simple way of restricting the caption width (some magical undocumented CSS class), or do I need to extend / adapt the client-side widget implementation?
Thanks,
William
What you need is FlexibleOptionGroup add-on.
Here is an example implementation:
#Override
protected void init(VaadinRequest request) {
Container cont = new IndexedContainer();
cont.addContainerProperty("caption", String.class, "");
// very long strings in the following setValue() methods
cont.getContainerProperty(cont.addItem(), "caption").setValue("I have...");
cont.getContainerProperty(cont.addItem(), "caption").setValue("So I ma...");
FlexibleOptionGroup fog = new FlexibleOptionGroup(cont);
fog.setCaption("FlexibleOptionGroup:");
fog.setItemCaptionPropertyId("caption");
fog.setMultiSelect(true); // force using CheckBoxes
VerticalLayout fogLayout = new VerticalLayout();
Iterator<FlexibleOptionGroupItemComponent> iter;
iter = fog.getItemComponentIterator();
while(iter.hasNext()) {
// OptionGroupItem part (CheckBox or RadioButton)
FlexibleOptionGroupItemComponent fogItemComponent = iter.next();
// CustomComponent part
Label caption = new Label(fogItemComponent.getCaption());
caption.setWidth(400, Unit.PIXELS);
fogLayout.addComponent(new HorizontalLayout(fogItemComponent, caption));
}
setContent(fogLayout);
}
The above code produces:

How do I add OnClick event on part of the text?

I need to add OnClick event to part of the text in installer.
So it will be like this "bla bla bla clickable text bla bla bla".
Also this text should be with WordWrap property set to True, since I don't know exact size of it because of bunch of localizations.
I was trying to split text into 3 parts so it will be like this
"Not-clickable-text1 clickable-text2 Not-clickable-text3"
but the problem begins when text3 should go to the next line of installer. It starts from position of text3.Left property, but I need it to start on next line from text1.Left property
There is no such thing like click-able part of the text in Inno.
You really need to use 3 "texts"- either TLabel or TNewStaticText - to build the whole sentence. The middle one will have set Font property to bold, underline or blue color (depends you want the link) and Cursor set to Hand, ... and of course the OnClick event.
Both components have property AutoSize and WordWrap which you can use.
AutoSize property set to true makes your component to fit width and height to text size. Set it to True for all 3 texts.
Position texts like this:
Text1.Left := 10; // 10 is just example
Text1.Top := 10; // 10 is just example
Text2.Left := Text1.Left + Text1.Width + 3; // 3 is space
if(Text1.Height > $Constant$) then
Text3.Top := Text1.Top + Text1.Height + 3 // Create new line
else
Text3.Left := Text2.Left + Text2.Width + 3;

Resources