PDA

View Full Version : Why didn't images with text alignment in QTextEdit?



tiaoweiliao
27th April 2016, 03:19
hi all.

I insert a text and images to QTextEdit , but I found no alignment.
11910

I try setAlignment(Qt::AlignBottom) in QTextEdit , but no change.

d_stranz
27th April 2016, 16:32
It looks to me like your text is aligned at the bottom. You are forgetting that Western characters have descenders - characters like 'y', 'g', and 'p' extend below the baseline of other characters like 'w', 'e', etc. If you make a text string for testing that contains characters with decenders, I think you will see that these characters do extend to the bottom of the text edit (minus whatever margin the widget is using).

Use QFontMetrics::descent() to obtain the number of pixels used for descenders in your font.

tiaoweiliao
29th April 2016, 03:49
Thank you, I got it.

How will the characters like 'y', 'g' at the bottom with image bottom alignment?

ignore characters like 'w', 'e'.

d_stranz
29th April 2016, 04:22
Sorry, I don't understand. Are you saying that you want your text to be bottom aligned with the image of the Chinese characters? You will probably get something better looking if you use Qt:: AlignVCenter on both of them. The it will not matter what the text is, both the text and the image will be vertically centered in the boxes.