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. Why my QWidget does not appear beside the other ones?
QtWS25 Last Chance

Why my QWidget does not appear beside the other ones?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwidgetqlayoutqmainwindowqboxlayout
2 Posts 2 Posters 1.3k 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 15 Jan 2016, 22:51 last edited by
    #1

    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 ;)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 16 Jan 2016, 00:53 last edited by
      #2

      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.

      1 Reply Last reply
      0

      1/2

      15 Jan 2016, 22:51

      • Login

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