08-28-2012 07:44 AM
To be honest, many things are difficult in cascades now, when will the next beta come?
We need draw in the form, it is reallly urgent.
08-28-2012 09:14 AM
Drawing in the form is a different topic than getting the width of a QString in a TextArea.
See:
https://www.blackberry.com/jira/browse/BBTEN-1
Also, look at http://code.google.com/p/skia/
If you have further questions that are not on the topic of finding the width of QString in a TextArea, please start a new thread.
Stuart
08-29-2012 04:36 PM - edited 08-29-2012 04:39 PM
I tried getting a QFont and using QFontMetrics, but as I expected I didn't succeed. The key line in the Qt documentation is: "Note that a QApplication instance must exist before a QFont can be used."
I found this but haven't finished playing with it:
https://developer.blackberry.com/native/beta/docum
Load the font type to use for our color menu and then determine the height of the menu for use later when we're determining which menu button is pressed. The function bbutil_load_font() generates the font symbols at the appropriate size for the screen of the BlackBerry 10 device through the use of dpi (dots per inch). We also need to calculate the point size for the font, which is specific to the device, using the font size (15 point) and the dpi of a BlackBerry PlayBook (170) as a reference value.
int dpi = bbutil_calculate_dpi(screen_cxt);
if (dpi == EXIT_FAILURE) {
fprintf(stderr, "Unable to calculate dpi\n");
return EXIT_FAILURE;
}
int point_size = (int)(15.0f / ((float)dpi / 170.0f ));
font = bbutil_load_font("/usr/fonts/font_repository/monot ype/arial.ttf", point_size, dpi);
if (!font) {
return EXIT_FAILURE;
}
float text_width, text_height;
bbutil_measure_text(font, "Color Menu", &text_width, &text_height);
menu_height = text_height + 10.0f + button_size_y * 4;
(See also: http://devblog.blackberry.com/2012/07/blackberry-1
Let me know if this helps!
Stuart
10-25-2012 03:34 PM
Hi Stuart,
i am having the same need i.e to calculate actual screen size (dpi/pt) of a string in a Label (or any other ui control)...
ran through the above code but:
"/usr/fonts/font_repository/monotype/arial.ttf"
how do i know what font is being used by the ui control (Label) ??
01-08-2013 09:30 AM
01-09-2013 01:58 PM
If you know the font being used, you can load it with free type and do so with a function available from the free type library. bb_util.c in the OpenGL samples and OpenGLView.cpp in GoodCitizenCascades includes functions to load a font, check on the size of text with the font, and render it in OpenGL.
01-09-2013 02:02 PM
01-10-2013 11:48 AM
You can't really. What are you going to use it for? Cascades isn't really designed for manual layouts. We recommend using the flow layouts over any absolute positioning so that your application can scale to different resolutions.
01-11-2013 11:27 PM
@MSohm
what if you need to do a custom button where the text displayed on the button changes based on the language?
cascades button simply fades out the text
for example
in EN, the width of the button can be 100px
in FR, w=180px
in ES, w=200px
now you will probably tell me to hardcode these sizes, but then we will have to hardcode for each language. And also, what if that text is simply dynamic?