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. QPainter native painting in QImage

QPainter native painting in QImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    i try to paint into a QImage with native painting:

    void paint(QPaintDevice *device)
    {
        QPainter painter(device);
        painter.beginNativePainting();
    
        glBegin(GL_POINTS);
          glColor3f(1, 0, 0); glVertex3f(0, 0, 0);
          glColor3f(0, 1, 0); glVertex3f(1, 0, 0);
          glColor3f(0, 0, 1); glVertex3f(1, 1, 0);
          glColor3f(1, 1, 0); glVertex3f(0, 1, 0);
        glEnd;
    
        painter.endNativePainting();
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QImage image(100,100, QImage::Format_RGB32);
        paint(&image);
        bool ok = image.save("test.jpg"); // ok = true
    
        return 0;
    }
    

    But the image doesn't show the points. Do i forget something?

    mrjjM 1 Reply Last reply
    0
    • beeckscheB beecksche

      Hi,
      i try to paint into a QImage with native painting:

      void paint(QPaintDevice *device)
      {
          QPainter painter(device);
          painter.beginNativePainting();
      
          glBegin(GL_POINTS);
            glColor3f(1, 0, 0); glVertex3f(0, 0, 0);
            glColor3f(0, 1, 0); glVertex3f(1, 0, 0);
            glColor3f(0, 0, 1); glVertex3f(1, 1, 0);
            glColor3f(1, 1, 0); glVertex3f(0, 1, 0);
          glEnd;
      
          painter.endNativePainting();
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QImage image(100,100, QImage::Format_RGB32);
          paint(&image);
          bool ok = image.save("test.jpg"); // ok = true
      
          return 0;
      }
      

      But the image doesn't show the points. Do i forget something?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @beecksche
      Hi
      Are you sure this can work ?
      I mean, Qimage must have an openGL context for this to be even possible to work.

      beeckscheB 1 Reply Last reply
      1
      • mrjjM mrjj

        @beecksche
        Hi
        Are you sure this can work ?
        I mean, Qimage must have an openGL context for this to be even possible to work.

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by beecksche
        #3

        @mrjj
        I'am definitily not sure ;-).

        I just saw, that the QPainter class paints into a QPaintDevice, and QImage is a QPaintDevice.
        I was not sure if the QPainter class translates the raw OpenGL commands and "paints" them into the QPaintDevice.

        So i will try it with a QWidget and see what happens :)

        Edit:
        So i tested the native painting:

        First of all, if i want to do the native painting in separate function it has no effect at all. So I inherited a class by QWidget and override the paintEvent function. But also the native painting has no effect, unless i use the QOpenGLWidget as base class.

        But here i don't understand the benefit, because you can use the functions described in the doc from QOpenGLWidget, paintGL and so on.

        1 Reply Last reply
        1

        • Login

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