Insert image in JFX Label in between two strings - javafx

How to insert an image in JFX Label but in between two Strings.Example : Text of JFX Label should be , "text 1 any text 2".
Is this possible dynamically ???

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.

Tab text alignment in QTabWidget

I am using QTabWidget class of Qt.
In TabWidget i am dynamically adding new tab and setting the TextElideMode to right to display the toolbutton in tabBar.
tabWidget = new QTabWidget(this);
m_addNewTab = new QWidget(tabWidget);
m_addNewGridLayout = new QGridLayout(m_addNewTab);
m_addNewWebView = new MyWebView(m_addNewTab);
widget = new QWidget(m_addNewTab);
tb = new QToolButton(widget);
tb->setFixedHeight(20);
tb->setText("<");
tb1 = new QToolButton(widget);
tb1->setFixedHeight(20);
tb1->setText(">");
m_horizontalLayout = new QHBoxLayout(widget);
m_horizontalLayout->addWidget(tb);
m_horizontalLayout->addWidget(tb1);
Please see the below screen shot for the output of the sample application.
When the current tab is selected then both the toolbutton should display and text elide mode should be right but when tab is not selected then toolbutton should not be displayed but text elide mode should be left.
Here in below screen shot i am able to hide and show the toolbutton depending on tab selection but when the tab is not selected text elide mode is setting as right so we are able to see the unnecessary space (check last tab). Setting the text elide mode left also not working because we have already set the toolbutton at left side.
Can someone guide me how to remove the space (last tab from screen shot) when there is not tab selected ?
You'll have to:
Keep track of tab index and corresponding holding widget (let's say std::map<int,QToolButton> toolbutton_by_index
When QTabWidget.currentChanged is emitted, deactivate all widgets except the selected
You can do the 2nd part like this:
std::for_each(toolbutton_by_index.begin(), toolbutton_by_index.end(),
[&index](auto pair){
(pair.first == index)?pair.second->hide():pair.second->show()});

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.

JavaFX Dynamic label text

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"));

How to set an image for a row?

I want to add text (at the beginning of a row) and an image at the end of the row.
I can set the text but how to set an image at the end of the row item in QTreeWidgetItem?
Just set for example two columns in QTreeWidget and then set text in first one and icon in second one:
QTreeWidgetItem *newItem = new QTreeWidgetItem;
newItem->setText(0, "Something");
newItem->setIcon(1, QIcon("Path to your icon"));
myTreeWidget->addTopLeveItem(newItem);
Or instread of setting icon you can just set foreground:
newItem->setForeground(QBrush(QPixmap("Path to your image")));
which may be better for your problem.

Resources