Results 1 to 5 of 5

Thread: How can I give TextEdit an outline?

  1. #1
    Join Date
    Apr 2019
    Posts
    8
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question How can I give TextEdit an outline?

    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

    example.png
    Last edited by UriTK; 10th April 2019 at 04:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I give TextEdit an outline?

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    UriTK (10th April 2019)

  4. #3
    Join Date
    Apr 2019
    Posts
    8
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I give TextEdit an outline?

    Quote Originally Posted by anda_skoa View Post
    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.


    Quote Originally Posted by anda_skoa View Post
    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.


    Quote Originally Posted by anda_skoa View Post
    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!
    Last edited by UriTK; 10th April 2019 at 09:54. Reason: rephrasing confusing stuff

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I give TextEdit an outline?

    Quote Originally Posted by UriTK View Post
    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,
    _

  6. #5
    Join Date
    Apr 2019
    Posts
    8
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I give TextEdit an outline?

    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.

Similar Threads

  1. Replies: 0
    Last Post: 4th November 2016, 00:27
  2. qgraphicspathitem how to get the outline
    By tf520 in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2014, 00:05
  3. line with outline
    By folibis in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2013, 10:22
  4. QGraphicTextItem and outline
    By eric_vi in forum Qt Programming
    Replies: 12
    Last Post: 17th October 2010, 21:47
  5. How can I rotate the font in TextEdit?
    By cslijy in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 08:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.