Results 1 to 5 of 5

Thread: Getting white text with black outline in most/all widgets

  1. #1
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Getting white text with black outline in most/all widgets

    So far I've made my way in the world of Qt by looking at examples and using the excellent docs. I've managed to make all the stuff work, but it doesn't have a wholesome look & feel.

    Part of the application is text overlayed on video, and to make that readable in all conditions I wanted white text with a black outline/glow/shadow. Since I didn't find a font-ish way to solve this, I ended up creating a widget where I paint 3 QLabels on top of each other (one white, and two black ones that are slightly offset). This works, but makes it hard getting other widgets with text to look similar. I also use QMessageBox, QMenu and QPushButton, and would like to make the text look similar there.

    Anything I have overlooked that can give me text in all widgets with the look I want? Or must I create my own QStyle or maybe override some central function to paint all text this way?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Getting white text with black outline in most/all widgets

    I don't think you can use QStyle for this, you can create all custom widgets (MyLabel, MyMessageBox, MyMenu, MyMenu...) and override the paintEvent() in all of them. In paintEvent() you could do something like this

    Qt Code:
    1. void MyLabel::paintEvent(QPaintEvent * event)
    2. {
    3. QPainter painter(this);
    4.  
    5. QFont font("Arial", 48, QFont::Normal, true);
    6. painter.setFont(font);
    7.  
    8. QRect top_rect = event->rect();
    9. QRect bot_rect = QRect(top_rect.left() + 4
    10. , top_rect.top() + 4
    11. , top_rect.right() + 4
    12. , top_rect.bottom() + 4);
    13.  
    14. painter.setPen(QPen(Qt::yellow));
    15. painter.drawText(bot_rect, text());
    16. painter.setPen(QPen(Qt::black));
    17. painter.drawText(top_rect, text());
    18. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Getting white text with black outline in most/all widgets

    Thanks a lot for the suggestion. Will test it as soon as my vacation is over.

    Edit: found the time to do a quick test now. Think I will find a way to make this work, though my test with QMessageBox didn't exactly do what I expected
    Attached Images Attached Images
    Last edited by anr78; 14th July 2011 at 21:52.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Getting white text with black outline in most/all widgets

    I posted a solution in another post
    http://www.qtcentre.org/threads/3411...ent-background

  5. #5
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Getting white text with black outline in most/all widgets

    Thanks! For some reason I do not get my e-mail alerts, so it takes a while before I notice replies

Similar Threads

  1. QPushButton: Outline white text in black on transparent background
    By Tito in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 20th July 2011, 08:16
  2. QSS, trying to make the text on the combo box WHITE not black.
    By technoViking in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2010, 00:57
  3. Image conversion black and white
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2010, 02:21
  4. İmage Convert Black and White
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2010, 06:08
  5. Displaying Text on Black and White Screen
    By Stobie in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 8th December 2009, 02:03

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.