4

I'm using Qt from python with PySide bindings. The main part of my application is the OpenGL view that can be resized to particular value (this is a simulator for testing my game in different resolutions of mobile devices). I use QGLWidget to render graphics from my game engine and QScrollArea for scrolling.

When I try to scroll GL view nothing happens - it just stays at the same place, but coordinates of QGLWidget are updated just fine which I see through print statements.

Playing around with resizing main window I've came to conclusion that everything inside QGLWidget is snapped to the bottom-left corner of currently visible area. So this would explain why I can't see scrolling.

Am I supposed to update projection matrix manually?

Vavius
  • 218
  • 2
  • 7
  • So you have `QGLWidget` inside `QScrollArea`? What exactly do you expect to happen when you scroll? – Fenikso Jan 08 '14 at 13:18
  • I expect that QGLWidget is moved with all it's drawings. I can move QGLWidget around by scaling the window. ScrollView alignment is set center and QGLWidget keeps centered in the window. But I can't move QGLWidget by scrolling, all GL drawings are snapped to bottom-left corner of currently visible rect of QGLWidget. – Vavius Jan 08 '14 at 18:30

1 Answers1

1

It sounds like some kind of parenting issue. This works as expected:

import sys
from PySide.QtGui import *
from PySide.QtOpenGL import *
from OpenGL.GL import *
from OpenGL.GLU import *

class GLWidget(QGLWidget):
    def __init__(self, *args, **kwargs):
        QGLWidget.__init__(self,  *args, **kwargs)

    def initializeGL(self):
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClearDepth(1.0)

    def resizeGL(self, w, h):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glViewport(0, 0, w, h)
        gluPerspective(45.0, w / h, 1, 1000)

    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()                   
        glTranslatef(0.0, 0.0, -6.0)            
        glBegin(GL_TRIANGLES)                 
        glColor3f(1.0, 0.0, 0.0)           
        glVertex3f(0.0, 1.0, 0.0)        
        glColor3f(0.0, 0.0, 1.0)           
        glVertex3f(-1.0, -1.0, 0.0)        
        glColor3f(0.0, 1.0, 0.0)           
        glVertex3f(1.0, -1.0, 1.0)        
        glEnd()

class Window(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)

        self.scroll = QScrollArea(self)
        self.glWidget = GLWidget(self.scroll)
        self.glWidget.resize(600, 400)
        self.scroll.setWidget(self.glWidget)

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.scroll)

        self.setLayout(self.layout)
        self.resize(400, 300)
        self.show()

app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())
  • OS: Windows 7 SP1 (32bit)
  • PySide: 1.2.1
  • Qt: 4.8.5
  • PyOpenGL: 3.0.2
Fenikso
  • 9,251
  • 5
  • 44
  • 72
  • Now it sounds like problem with my setup. I'm using PySide 1.2.1, Qt 4.8.5, Mac OS X 10.8.5. Your triangle is fixed and doesn't move with scroll bars – Vavius Jan 08 '14 at 20:47
  • I am on Windows 7. Library versions seem the same, I can check PyOpenGL version tomorrow. – Fenikso Jan 08 '14 at 21:38
  • 1
    Maybe this problem is related to Cocoa limitations when dealing with GLViews. Here is the line from Qt docs about it: "QGLWidget can’t have any sibling widgets placed ontop of itself. This is due to limitations in the Cocoa API and is not supported by Apple." – Vavius Jan 08 '14 at 21:45
  • Maybe. There is no way for me to tell. Sorry. – Fenikso Jan 09 '14 at 09:11
  • May be interesting to try the same in Java with Swing and JOGL. Because there are `GLCanvas` and `GLJPanel`. The second being slower but with better compatibility with Swing GUI. I suspect the first to behave the same if it is OS limitation. – Fenikso Jan 09 '14 at 09:17