How can I show text by QWindow?
-
Like QGLWidget ,I can use rendertext() ,but now I am using QWindow + QOpengl 3.3, I don't know how to do :-(
-
Hi, welcome to devnet.
You can use "QOpenGLPaintDevice":http://qt-project.org/doc/qt-5/qopenglpaintdevice.html to draw text with QPainter.
See the "QWindow OpenGL example":http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html for more details. -
[quote author="chrisaverage" date="1411912911"]Hi, welcome to devnet.
You can use "QOpenGLPaintDevice":http://qt-project.org/doc/qt-5/qopenglpaintdevice.html to draw text with QPainter.
See the "QWindow OpenGL example":http://qt-project.org/doc/qt-5/qtgui-openglwindow-example.html for more details.[/quote]Thank you very much.I try to use QOpenGLPaintDevice ,but it dosen't work!
I have see that example .but in fact it doesn't use the QOpenGLPaintDevice. And Can you give me some example,like code...:-)
-
I'm not gonna write again what is already in the official example. It does use QOpenGLPaintDevice. Are you sure you read it?
This is the relevant code from the link above (with my comments):
@
void OpenGLWindow::render(QPainter *painter)
{
//delete that line and put your text drawing here eg.
//painter->drawText(10, 10, "Hello world!");
Q_UNUSED(painter);
}void OpenGLWindow::render()
{
//Oh look! An QOpenGLPaintDevice :)
if (!m_device)
m_device = new QOpenGLPaintDevice;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); m_device->setSize(size()); QPainter painter(m_device); render(&painter);
}
@