Unsolved QPainter and QOpenGLWidget - Text Corruption
-
This kinda follows on from this post from a few years back:
https://forum.qt.io/topic/64310/rendering-text-in-qopenglwidget
When attempting to use
QPainter
to draw some text from within thepaintGL
function of aQOpenGLWidget
, some kind of corruption is occurring on the font glyphs:This text should just say "Hello there" but clearly does not.
Within the
paintGL
function, I have the following code:QPainter p(this); p.setFont(QFont("Verdana", 16)); p.setPen(Qt::white); p.setBrush(Qt::transparent); p->drawText(500, 500, 100, 20, Qt::AlignCenter, "Hello there");
Any pointers would be greatly appreciated.
-
When you're following this post then you're missing
painter.beginNativePainting();
but don't know if it help though.
-
@Christian-Ehrlicher unfortunately I’ve already tried that and it makes zero difference.
-
Hi
Using the code from the other post#include <QApplication> #include <QOpenGLWidget> #include <QOpenGLFunctions> #include <QPainter> class MyOpenGLWidget : public QOpenGLWidget { public: MyOpenGLWidget() {} void initializeGL() { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); f->glClearColor(1.f, 1.f, 1.f, 1.f); } void resizeGL(int w, int h) { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); f->glViewport(0, 0, w, h); } void paintGL() { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); f->glClear(GL_COLOR_BUFFER_BIT); QPainter painter(this); painter.setPen(Qt::black); painter.setFont(QFont("Arial", 56)); painter.drawText(0, 0, width(), height(), Qt::AlignCenter, "Hello World!"); painter.end(); } }; int main(int argc, char **argv) { QApplication app(argc, argv); MyOpenGLWidget wnd; wnd.resize(400, 300); wnd.show(); return app.exec(); }
Tried on win 10, win 7 and linux and had no text corruption.
Where are you seeing this ?