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. Painting over a QGLWidget fails

Painting over a QGLWidget fails

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 484 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.
  • N Offline
    N Offline
    neon29
    wrote on last edited by
    #1

    I am trying to paint over a QGLWidget by means of a QPainter as explained in various tutorials. In my paintGL() function, I have two cases. Indeed, if there is nothing to draw in OpenGL then I only use the QPainter to draw 2 lines (this part does work). However, when there is something to draw with OpenGL, I first use an OpenGL function such as drawElements() and then I use my painter to overpaint the widget, but in this case I can only display my OpenGL "objects", the two lines being invisible.

    Here is the code of my paintGL method:

    def paintGL(self): 
    
    
            glClearColor(0, 0, 0, 1)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    
    
    
            if np.array(self.objects).size:
    
                print('there are %i objects'%(len(self.objects)))
                #                
    
    
                # active shader program
                glUseProgram(self.shaderProgram)
    
                for i, obj in enumerate(self.objects):        
    
                    loc_pos = glGetAttribLocation(self.shaderProgram, "position")
                    glEnableVertexAttribArray(loc_pos)
                    glBindBuffer(GL_ARRAY_BUFFER, obj.VBO[0])
                    glVertexAttribPointer(loc_pos, 2, GL_FLOAT, False, 0,  ctypes.c_void_p(0))
    
                    loc_col = glGetAttribLocation(self.shaderProgram, "color")
                    glEnableVertexAttribArray(loc_col)
    
                    glBindBuffer(GL_ARRAY_BUFFER, obj.VBO[1])
                    glVertexAttribPointer(loc_col, 4, GL_FLOAT, False, 0,  ctypes.c_void_p(0))
    
    
                    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, obj.VBO[2])
                    glDrawElements(GL_TRIANGLES, obj.indices.size, GL_UNSIGNED_INT, ctypes.c_void_p(0))
    
    
                glUseProgram(0)
    
    
                painter = QtGui.QPainter()
                painter.begin(self)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                print(painter.isActive())
    
    
                pen = QtGui.QPen(QtGui.QColor(255,0,0), 10)
    
                x = 100
                y= 100       
    
                # clean previous drawings        
                painter.fillRect(self.rect(),QtGui.QBrush(QtGui.QColor(0,0,0)) )
                painter.setPen(pen)
    
                currentFont = painter.font()
                currentFont.setPointSize(currentFont.pointSize()*4)
                painter.setFont(currentFont)
                painter.drawLine(x, 0, x, self.height())
                painter.drawLine(0, y, self.width(), y)    
    
    
                painter.end()
    
            else:
    
                print('No data in objects ==> no drawing')
                painter = QtGui.QPainter()
                painter.begin(self)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                print(painter.isActive())
    
    
                pen = QtGui.QPen(QtGui.QColor(255,0,0), 10)
    
                x = 100
                y= 100       
    
                # clean previous drawings        
                painter.fillRect(self.rect(),QtGui.QBrush(QtGui.QColor(0,0,0)) )
                painter.setPen(pen)
    
                currentFont = painter.font()
                currentFont.setPointSize(currentFont.pointSize()*4)
                painter.setFont(currentFont)
                painter.drawLine(x, 0, x, self.height())
                painter.drawLine(0, y, self.width(), y)    
    
    
                painter.end()
    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