Design/Layout question (PySide)



  • Hey guys, I've been playing around with PySide for a while now, it rocks my socks off! I started with the designer, but I actually found it hard to achieve specific layouts. So after googling, I found that some guys recommended doing it with code instead, which is what I'm doing now.

    However, I really struggle to achieve the specific layout I want, I've attached a couple of images. The original (the one I have now) first: "Link <original window>":http://s27.postimg.org/4vu8kheab/app_original.jpg

    And this is what I want:
    !http://s28.postimg.org/hc4s7b8xp/app_new.jpg(What I want)!

    I would appreciate it if anyone could point me in the right direction here, and if the way I've written the code is wrong/messy or anything, please tell me :)

    Here's the code I have so far:
    @import sys
    from PySide import QtCore, QtGui

    class Window(QtGui.QWidget):
    def init(self, parent=None):
    super(Window, self).init(parent)
    #Create the layouts
    layout_main = QtGui.QVBoxLayout()
    layout_left = QtGui.QVBoxLayout()
    layout_right = QtGui.QVBoxLayout()
    layout_bottom = QtGui.QHBoxLayout()
    #Create the frames
    frame_main = QtGui.QFrame()
    frame_left = QtGui.QFrame()
    frame_right = QtGui.QFrame()
    #Set options for the layouts
    layout_left.setAlignment(QtCore.Qt.AlignTop)
    layout_right.setAlignment(QtCore.Qt.AlignTop)
    #Set options for the frames
    frame_left.setMinimumWidth(300)
    frame_left.setFrameShape(QtGui.QFrame.StyledPanel)
    frame_right.setMinimumWidth(300)
    frame_right.setFrameShape(QtGui.QFrame.StyledPanel)
    #Set the style to Cleanlooks
    QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Plastique'))

        #Add widgets to the left and right layout
        widget_cal1 = QtGui.QCalendarWidget(self)
        widget_cal2 = QtGui.QCalendarWidget(self)
        widget_cal1.setFixedHeight(220)
        widget_cal2.setFixedHeight(220)
        btn_1 = QtGui.QPushButton('Button 1')
        btn_2 = QtGui.QPushButton('Button 2')
        layout_left.addWidget(widget_cal1)
        layout_right.addWidget(widget_cal2)
        layout_left.addWidget(btn_1)
        layout_right.addWidget(btn_2)
    
        #Add lower buttons
        btn_x = QtGui.QPushButton('Button X')
        btn_y = QtGui.QPushButton('Button Y')
        layout_bottom.addWidget(btn_x)
        layout_bottom.addWidget(btn_y)
        #Add the buttons to the left layout
        layout_left.addLayout(layout_bottom)
    
        #Create a QSplitter widget and add the left and right frames into it
        splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
        splitter.addWidget(frame_right)
        splitter.addWidget(frame_left)
        #Set the QSplitter to not bein collapsable
        splitter.setCollapsible(0, False)
        splitter.setCollapsible(1, False)
        #Add the splitter to the mainLayout
        layout_main.addWidget(splitter)
    
        #Set the layout for the frames
        frame_main.setLayout(layout_main)
        frame_left.setLayout(layout_left)
        frame_right.setLayout(layout_right)
    
        self.setLayout(layout_main)
    
        self.setWindowTitle("Split Layout")
        self.resize(920, 420)
    

    #Open the window
    if name == 'main':
    app = QtGui.QApplication(sys.argv)
    w = Window()
    w.show()
    sys.exit(app.exec_())@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.