For example, I want set the QFont weight 120 pixels or 1.5mm. Now, the weight has been defined by enumeration of 0~99, that's not my need.
I upload two images for example:
normal text
expand text
You want to use the pointSize property, not weight.
setPointSize
Related
I have a custom tool button where when checked the font become bold. When happens, the size of the text increase and consequently the ToolButton shrink or stretch accordly. How can i pre calculate the correct fixed size for the text inside the button?
You can use FontMetrics QML type for this purpose. Setup the FontMetrics object with the same font and style you are using for your text, then call an appropriate method of your FontMetrics instance like boundingRect or tightBoundingRect and resize your button based on the results.
If you just want to keep your ToolButton to a fixed size that can contain the normal and bold font without auto-resizing, you can just get the size for the bold text using the FontMetrics instance and set the button size accordingly.
For convenience you can also use TextMetrics QML type. The advantage is that the boundingRect and tightBoundingRect are properties and you can bind to them.
The latter is preferred for your use-case.
How could we extend the NamedSize to get a larger text?
The below LOC gives out a large size but I would like to have a larger one and yet not hardcoded:
myLabel.TextSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
Thank you.
https://developer.xamarin.com/api/type/Xamarin.Forms.NamedSize/
MEMBER NAME DESCRIPTION
Default The default font size.
Large A Large font size, for titles or other important text elements.
Medium A default font size, to be used in stand alone labels or buttons.
Micro The smallest readable font size for the device. Think about this like legal footnotes.
Small A small but readable font size. Use this for block of text.
A larger font size does not exist in the NamedSize Enumeration. You could create a custom property MyFontSize and set it to a different value, based on the current device and have your label's size bound to that property.
It's still hard-coded, but you'd have to play around with size values to make it look the way you want on each device.
I have a QLabel used to display a QImage. In design mode the label geometry is (9,65), 1384 × 616 as listed in the Property Editor. At runtime when the MainWindow containing the label constructs (i.e. ui->setupUi(this)), the label always appears to be 100×30 at startup which leads to images displaying only a really small portion.
Why do I have to set it to a fixed size to be anything but 100×30?
Thanks in advance for any help.
Qt does not really use the defined geometry, only the defined layouts.
Without layout and not fixed size, all components will have their default size.
So usually you need to set a layout for the container containing the component and then set the size policies of the component.
For an image, you should probably use a fixed size hint.
The resulting icon is oversized, even with font-size set to 16px, it looks like 32px or even more.
I used the [Octicons][2] approach to build the icons, so Glyphs setup looks as follows:
Units per Em is 2048
Metrics is exactly like Octicons
Glyph width is set to 2048
Grid spacing is set to 32
My mistake was to create glyphs with setting of "units per em" equal to 1000. After changing the value, already existing glyphs do not update automatically, you should press the button next to the setting.
How do I convert my font on a QGraphicsObject from point size to pixel size? I need to do this so the fonts will look right when I print my QGraphicsScene using QGraphicsScene::render().
Probably class QFontMetrics will do the job. Just create your desired QFont, set It's point size. Then create QFontMetrics object on your QFont.