Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I show text by QWindow?
Forum Updated to NodeBB v4.3 + New Features

How can I show text by QWindow?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sdaujiaojiao
    wrote on last edited by
    #1

    Like QGLWidget ,I can use rendertext() ,but now I am using QWindow + QOpengl 3.3, I don't know how to do :-(

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisaverage
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sdaujiaojiao
        wrote on last edited by
        #3

        [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...:-)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisaverage
          wrote on last edited by
          #4

          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);
          

          }
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved