This question already has answers here:
How to calculate the pixel width of a String in JavaFX?
(4 answers)
Closed 5 years ago.
I need to know the size of a text using a textlayout object.
I found the following bunch of codes
final TextLayout LAYOUT = Toolkit.getToolkit().getTextLayoutFactory().createLayout();
LAYOUT.setContent(text != null ? text : "", font.impl_getNativeFont());
LAYOUT.setLineSpacing(1.0f);
LAYOUT.setWrapWidth(100.0f);
LAYOUT.setBoundsType(TextLayout.BOUNDS_CENTER);
return LAYOUT.getBounds().getHeight();
The code is working properly except I have a warning message concerning getNativeFont which seems to be deprecated, knowing that what I need is the height of the text
So my question : What is the appropriate method ?
Thanks in advance !
Thank you,
It is working for me:
Text theText = new Text(theLabel.getText());
theText.setFont(theLabel.getFont());
double width = theText.getBoundsInLocal().getWidth();
Related
This question already has answers here:
Escaping backslash (\) in string or paths in R
(4 answers)
Closed 1 year ago.
In how to change working directory more easily?
Currently, if we use 'setwd',we have to add many '\', sometimes it's boring
Is there any easier way for this ? (Just like Python can add 'r' )
setwd('C:\Users\Administrator\Desktop\myfolder') # can't work
setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
You could use r (for raw string) and add parenthesis:
> r"(C:\Users\Administrator\Desktop\myfolder)"
[1] "C:\\Users\\Administrator\\Desktop\\myfolder"
>
And now:
setwd(r"(C:\Users\Administrator\Desktop\myfolder)")
Or reading from clipboard automatically adds the extra slashes:
setwd(readClipboard())
This question already has answers here:
Get filename without extension in R
(9 answers)
Find file name from full file path
(4 answers)
Closed 3 years ago.
I have several download links (i.e., strings), and each string has different length.
For example let's say these fake links are my strings:
My_Link1 <- "http://esgf-data2.diasjp.net/pr/gn/v20190711/pr_day_MRI-AGCM3-2-H_highresSST_gn_20100101-20141231.nc"
My_Link2 <- "http://esgf-data2.diasjp.net/gn/v20190711/pr_-present_r1i1p1f1_gn_19500101-19591231.nc"
My goals:
A) I want to have only the last part of each string ended by .nc , and get these results:
pr_day_MRI-AGCM3-2-H_highresSST_gn_20100101-20141231.nc
pr_-present_r1i1p1f1_gn_19500101-19591231.nc
B) I want to have only the last part of each string before .nc , and get these results:
pr_day_MRI-AGCM3-2-H_highresSST_gn_20100101-20141231
pr_-present_r1i1p1f1_gn_19500101-19591231
I tried to find a way on the net, but I failed. It seems this can be done in Python as documented here:
How to get everything after last slash in a URL?
Does anyone know the same method in R?
Thanks so much for your time.
A shortcut to get last part of the string would be to use basename
basename(My_Link1)
#[1] "pr_day_MRI-AGCM3-2-H_highresSST_gn_20100101-20141231.nc"
and for the second question if you want to remove the last ".nc" we could use sub like
sub("\\.nc", "", basename(My_Link1))
#[1] "pr_day_MRI-AGCM3-2-H_highresSST_gn_20100101-20141231"
With some regex here is another way to get first part :
sub(".*/", "", My_Link1)
This question already has answers here:
How to use LOAD_FILE to load a file into a MySQL blob?
(6 answers)
Closed 4 years ago.
INSERT INTO items (id,name,image,price) VALUES('1','iphone 5s',LOAD_FILE('C:\xampp\htdocs\project\1.jpg'),300);
this statement cause error
INSERT INTO items (id,name,image,price) VALUES('1','iphone 5s',LOAD_FILE('C:\xampp\htdocs\project\1.jpg'),300)
MySQL said: Documentation
here is the error
#1048 - Column 'image' cannot be null
Please double check the file path of your "1.jpg" or maybe look at the image format whether it is .jpg or .png.
Else, try this format:
LOAD_FILE('../1.jpg')
"Different backslash position"
I do not think you should mention the C:/xampp/htdocs/project because you are already in the project folder when you run your code.
Hopefully it is working.
You must escape backslashes in any string:
... LOAD_FILE('C:\\xampp\\htdocs\\project\\1.jpg') ...
Or, since MySQL will 'correctly' interpret forward-slashes, even on Windows:
... LOAD_FILE('C:/xampp/htdocs/project/1.jpg') ...
(I assume image is declared BLOB or MEDIUMBLOB?)
This question already has answers here:
How to specify a unicode character using QString?
(4 answers)
Closed 7 years ago.
I would like to be able to display Unicode in QGraphicsTextItem (or a subclass of it).
The only way to set text in QGraphicsTextItem seems to be
setPlainText(text);
Trying
setPlainText(QString::fromUtf8("Caf\x00e9 Frap\x00e9"));
or
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Café Frapé");
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
setPlainText("Caf\x00e9 Frap\x00e9");
I get:
Caf? Frap?
It seems that no matter what I do (which I am not sure is correct) I do not get the output right...
Do QGraphicsTextItem support unicode ? Is maybe the setPlainText function at fault - but then what are the alternatives ? (I looked into setDocument but it also sets plain text...)
Edit - copying the special characters inside the QGraphicsTextItem works, once on screen, but still unable to place any unicode from code.
In a class inheriting QGraphicScene, I used:
QString text(QString::fromUtf8(xt.text));
...
QGraphicsTextItem *t = addText(text = text.replace("\\n", "\n"), font);
The dot source is utf8:
digraph so {
Café -> Frapé
}
And the rendering:
You can find here the C++ code.
I think you should use the
QGraphicsTextItem item.
item.setHtml( "Café Frapé" );
function instead of the mentioned. Read this QGraphicsTextItem::setHtml.
This question already has answers here:
RGB to hex and hex to RGB
(59 answers)
Closed 8 years ago.
I want to make the background of an element semi-transparent in css. I am aware that there is a way to do this using
background-color: rgba(100,100,100,0.5);
but I am trying to dynamically create the css in my rails application, and the variable I am using is a hex code. Is there an equivalent to rgba() that will allow me to use my hex code as a parameter?
You can convert your hex code to rgb here: http://www.javascripter.net/faq/hextorgb.htm
Edit:
Then he can do it in ruby.
Create a function that takes the hex-string, split the string in three parts and convert each part like this:
hex_part = "ff"
hex_part.to_i 16
Edit 2:
hex = "ff8800"
hex_parts = hex.scan(/.{1,2}/)
hex_parts[0] = hex_parts[0].to_i 16 // Will make first part to dec.
hex_parts[1] = hex_parts[1].to_i 16
hex_parts[2] = hex_parts[2].to_i 16
dec = hex_parts.join(",") // Join the parts with a "," and you will get "255,136,0".
if you enclose your element in a div tag with, let's say, class="opac", you can just use jQuery that way:
$('.opac').animate({opacity: .2},500);
this will make your 'opac' object's opacity to 20% when a particular event is triggered, for instance, if a link within a div tagged with Add_Something is clicked:
$('#Add_Something a').click(function() {
$('.opac').animate({opacity: .2}, 500);
});
'500' is just the speed in which the object will become semi-transparent ...