Results 1 to 3 of 3

Thread: QPainter drawFont() draws corrupt glyphs

  1. #1
    Join Date
    Feb 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QPainter drawFont() draws corrupt glyphs

    I’m using Qt 5.2, on Windows 7, MinGW 32 bit version. I’m trying to overlay some 2d text over an OpenGL 3.3 context using QPainter.

    Here’s the code I’m using to set up the font:
    Qt Code:
    1. m_font = QFont ("Times", 15, QFont::Light, true);
    To copy to clipboard, switch view to plain text mode 

    Here’s the code I’m using for drawing:
    Qt Code:
    1. if (!m_paintDevice){
    2. m_paintDevice = new QOpenGLPaintDevice;
    3. }
    4.  
    5. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    6.  
    7. m_paintDevice->setSize(size());
    8.  
    9. QPainter painter(m_paintDevice);
    10. painter.setRenderHint(QPainter::Antialiasing);
    11. painter.beginNativePainting();
    12.  
    13. // OpenGL draw calls go here.
    14.  
    15. painter.endNativePainting();
    16.  
    17. m_defaultPen.setColor(Qt::white);
    18.  
    19. painter.setPen(m_defaultPen);
    20. painter.setFont(m_font);
    21. painter.drawText(m_defaultRect, Qt::AlignCenter, "This is a test.");
    To copy to clipboard, switch view to plain text mode 

    All other code is pretty much identical to the example found here https://qt-project.org/doc/qt-5.0/qt...nglwindow.html.

    This is the result I’m getting:
    mGVoBeT.png

    I’ve tried multiple different font families (Arial, Compacta, etc.), yet this problem persisted. The only thing that can slightly mitigate it, is the increase in QFont size (50+ has little to none of these distortions).

    Does anyone know how to solve this problem?

  2. #2
    Join Date
    Feb 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPainter drawFont() draws corrupt glyphs

    Strange. I've compiled my program on Ubuntu, and everything looks fine there. Seems that this is a Windows specific issue.
    Unfortunately, Win7/8 are the main platforms that we'll be deploying to. What is qt doing differently on Windows?

  3. #3
    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: QPainter drawFont() draws corrupt glyphs

    Since this involves OpenGL, it might depend on which of the two approaches it is using.

    One is to use native OpenGL, but I think that needs to be provided by the graphics card vendor.
    Another one is using ANGLE, to somehow translate GL into Direct3D.

    There might even be a way to just use whatever Microsoft provides for OpenGL, but as far as I know that is not anywhere near what all other platforms provide.

    Cheers,
    _

Similar Threads

  1. Qt draws block diagram
    By Imio in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2012, 08:38
  2. Fastest way to clear a bitmap that painter draws on
    By PhilippM in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2011, 15:51
  3. QTextLayout draws text outside the widget
    By alpinista in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 07:25
  4. Replies: 5
    Last Post: 11th March 2008, 14:38
  5. atomicy in gui draws
    By elcuco in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2006, 21:02

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.