can anybody tell me what's wrong in the following simple source code. In the picture below you can see my problem. I want a widget which consists of a menu and a QGLWidget, but the QGLWidget overlaid the menu. If I use QtGui.QWidget instead it works fine. How can I increase the space between these elements?
diagram 1:
code of QGLWidget :
class Profile(QtOpenGL.QGLWidget):
def __init__(self, parent = None):
super(Profile, self).__init__(parent)
def initializeGL(self):
GL.glClearColor(1.0, 1.0 , 1.0, 1.0)
def paintGL(self):
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
code of test widget which works fine:
class TestWidget(QtGui.QWidget):
def __init__(self, parent = None):
super(TestWidget, self).__init__(parent)
editor = QtGui.QTextEdit()
grid = QtGui.QGridLayout()
grid.addWidget(editor, 1,1)
self.setLayout(grid)
code of main widget:
class ProfileDetectWidget(QtGui.QWidget):
def __init__(self, parent = None):
super(ProfileDetectWidget, self).__init__(parent)
self.ogl_widget = Profile()
# self.ogl_widget = TestWidget()
grid = QtGui.QGridLayout()
grid.addWidget(self.ogl_widget, 2,1)
self.createActions()
self.createMenus()
self.setLayout(grid)
self.resize(420,320)
def createActions(self):
self.openAct = QtGui.QAction('Open...', self)
def createMenus(self):
fileMenu = QtGui.QMenu("File", self)
fileMenu.addAction(self.openAct)
menubar = QtGui.QMenuBar(self)
menubar.addMenu(fileMenu)
if __name__ == '__main__':
app = QtGui.QApplication(["PyQt OpenGL"])
widget = ProfileDetectWidget()
widget.show()
app.exec_()
In the code of the main widget I changed
grid = QtGui.QGridLayout()
grid.addWidget(self.ogl_widget, 2,1)
to
space = QtGui.QSpacerItem(0,15)
grid = QtGui.QGridLayout()
grid.addItem(space)
grid.addWidget(self.ogl_widget, 2,1)
and it seems to work.