PDA

View Full Version : How can I give TextEdit an outline?



UriTK
10th April 2019, 02:40
I've been looking into what my different options are as far as drawing a simple 2px black outline around my QTextEdit. What would be the best way?

Drawing an outline separate from QTextEdit with the same string of text and sync-ing them up?

Somehow using insertHtml to give it an outline? Some other way I have not realized is possible?

As far as using something like QPainter, I'm pretty sure that should be possible somehow but I don't know where to start to make it draw 2 pixels going out the edges of the font.

Here is an example of what the end product should look like, to avoid confusion with borders. Just a simple white text with a black outline

13081

anda_skoa
10th April 2019, 07:11
Your question is confusing.

You seem to want to draw text that has an outline and is "empty" inside, but then you say you want to draw around a QTextEdit.

Drawing a frame around a QTextEdit is easy, you simply put the QTextEdit into a QFrame container.

For drawing text like in the attached image, the easiest way is likely to take a font that does that.

Cheers,
_

UriTK
10th April 2019, 08:44
Your question is confusing.
You seem to want to draw text that has an outline and is "empty" inside, but then you say you want to draw around a QTextEdit.
Ah! Sorry, I'm probably very confused on how these QT functions work in general, since I'm kind of semi winging purely out of experience on other languages. Let me elaborate to see if I'm horribly wrong somewhere

My goal here is to rework the portion of the code I've already got, which draw letters/string and is just being defined as ui_vp_message = new QTextEdit(ui_vp_chatbox);, said "Rework" would be to tweak said code so the text has an outline, and if possible being able to choose how wide said outline is.

The way I understand it I could use QPainter instead of QTextEdit to draw a black font outline and then fill it in with white, but that'd requiere me to rework a whole lot of code, which is fine unless I can avoid it, and I also wanted to let the user have the *choice* of using outlines or not via setting values on config files.
But then again I'm probably completely missunderstanding how QPainter and QTextEdit even relate to each other.



Drawing a frame around a QTextEdit is easy, you simply put the QTextEdit into a QFrame container.
Ah, I don't want to draw a frame or a border around QTextEdit, assuming I understood that correctly. I just want to outline the text itself. If you're suggesting that for the light blue background I added, I just chose that so the outline would stick out.



For drawing text like in the attached image, the easiest way is likely to take a font that does that.
If you mean getting a family font that is an outline font itself, I thought about doing that, yeah. The problem with that is that the fonts utilized will be almost entirely provided by the user, so as I said, I'd like the outline to be optional.
Also! To clarify, I don't want it to be empty inside, I want it to be white on the fill and black on the outline.


TL;DR: I guess what I'm trying to ask is if there is any simple-ish way I can give my QTextEdit an outline, if I'm greatly missunderstanding the core concepts of how QT draws text, or if I should just keep looking at the docs trying to figure stuff out.
Also, sorry for my jank! And thanks for your patience, and actually calling out my confusing stuff!

anda_skoa
10th April 2019, 12:47
But then again I'm probably completely missunderstanding how QPainter and QTextEdit even relate to each other.

QPainter is just the low level drawing API, QTextEdit ultimately uses it to draw its content.

The QTextEdit widgets is a pretty versatile component due the text layout engine it uses.
This engine is QTextDocument. See QTextEdit::document().

It allows you to manipulate text very similar to a text processor, e.g. having different formats for different sections of text.

One of the involved classes, QTextCharFormat, allows to set the pen used to draw text outline. See QTextCharFormat::setTextOutline().

I haven't used this particular feature myself yet, but this could be what you are looking for.

Cheers,
_

UriTK
10th April 2019, 17:11
I believe this is just what I wanted, I did not notice how customizable QPen is.

Also, thanks for pointing out exactly "What" QPainter is in relation to QTextEdit!
I'm not sure if QTCentre has a general rule for "avoid posts that just say 'thanks'", but still, thank you for putting up with us frustrated newbies!

Now, cheers.