Why my QWidget does not appear beside the other ones?
-
Hi!
My GLWidget (inherited from QtOpenGL.QGLWidget) does not appear on screen, while it should be visible at the right of the other widgets. However, when I switch from an horizontal layout:
layout_final = Qtgui.QHBoxLayout()
to a vertical one:
layout_final = Qtgui.QVBoxLayout()
my GL widget does appear under the other widgets, but I want it to be on the right of the other widgets, not under.
Here is the full code:
class MainWindow(QtGui.QMainWindow): def __init__(self): super(MainWindow, self).__init__() # create layout layout_before_final = QtGui.QVBoxLayout() layout_final = QtGui.QHBoxLayout() layout = QtGui.QGridLayout() layout1 = QtGui.QGridLayout() self.groupBox = QtGui.QGroupBox('Set HDF5 file') self.groupBox1 = QtGui.QGroupBox('Current HDF5 file') # instance widgets # first box self.setH5Button = QtGui.QPushButton('set H5') self.currentH5LineEdit = QtGui.QLineEdit('') layout.addWidget(self.setH5Button, 0,0) layout.addWidget(self.currentH5LineEdit, 0, 1) self.groupBox.setLayout(layout) # second box self.channelsLabel = QtGui.QLabel('Channel') self.channelsComboBox = QtGui.QComboBox() self.levelsLabel = QtGui.QLabel('Level') self.levelsComboBox = QtGui.QComboBox() layout1.addWidget(self.channelsLabel, 0, 0, 1, 1) layout1.addWidget(self.channelsComboBox, 0, 1, 1, 1) layout1.addWidget(self.levelsLabel, 1, 0, 1, 1) layout1.addWidget(self.levelsComboBox, 1, 1, 1, 1) self.groupBox1.setLayout(layout1) # create QWidget to gather the two previous boxes self.widget = QtGui.QWidget() layout_before_final.addWidget(self.groupBox) layout_before_final.addWidget(self.groupBox1) self.widget.setLayout(layout_before_final) # GL widget self.widgetGL = MyWidget() # create a final widget to add the GL widget self.finalWidget = QtGui.QWidget() layout_final.addWidget(self.widgetGL) layout_final.addWidget(self.widget) self.finalWidget.setLayout(layout_final) self.setCentralWidget(self.finalWidget) self.setWindowTitle('PyPractis') self.resize(640, 480) def main(): import sys app = QtGui.QApplication(sys.argv) w = MainWindow() w.resize(640, 480) w.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
Hope someone could help ;)
-
I'm not that fluent in python, but
layout_final.addWidget(self.widgetGL) layout_final.addWidget(self.widget)
Horizontal layouts add stuff left to right, so, if anywhere, the GL widget would be on the left, not on the right.
I don't think a GL widget has any minimum size. It might be that the other widgets have "greedy" horizontal size policies (I think a label does by default). Try setting a minimum width or an expanding horizontal size policy on the GL widget.