1.11M Members

how should I access the layout in a different moudule in PySide

 
0
 

I have implemented a toolbar that has several QPushButtons inside QVBoxLayout, however I have implemented it in toolbar_UI.py

from PySide import QtCore,QtGui

class ToolBarUI(QtGui.QWidget):
    def __init__(self,*args,**kwargs):
        super(ToolBarUI,self).__init__(*args,**kwargs)
        self.floatingToolBar()

    def sizeHint(self):
        return QtCore.QSize(65,45)

    def buttons(self):

        self.emlSel = QtGui.QAction("Email Selected", self)

        self.emlScn = QtGui.QAction("Email this Scene", self)

        self.emlBufr = QtGui.QAction("Email Current Frame Buffer", self)
        self.menu = QtGui.QMenu(self)
        self.menu.addAction(self.emlSel)
        self.menu.addAction(self.emlScn)
        self.menu.addAction(self.emlBufr)

        x,y=5,45
        self.btnVLay=QtGui.QVBoxLayout(self)
        self.setLayout(self.btnVLay)
        self.btnVLay.setContentsMargins(0,0,0,0)

        self.incSavbtn=QtGui.QPushButton("Save")
        self.incSavbtn.setMinimumSize(QtCore.QSize(x,y))
        self.emailbtn=QtGui.QPushButton("Email")
        self.emailbtn.setMinimumSize(QtCore.QSize(x,y))
        self.emailbtn.setMenu(self.menu)
        self.upldbtn=QtGui.QPushButton("Upload")
        self.upldbtn.setMinimumSize(QtCore.QSize(x,y))
        self.setPrjbtn=QtGui.QPushButton("Set Project")
        self.setPrjbtn.setMinimumSize(QtCore.QSize(x,y))
        self.setThumb=QtGui.QPushButton("Set thumb")
        self.setThumb.setMinimumSize(QtCore.QSize(x,y))
        self.shwMatbtn=QtGui.QPushButton("Show Material")
        self.shwMatbtn.setMinimumSize(QtCore.QSize(x,y))
        self.fixtexbtn=QtGui.QPushButton("Fix Texture Paths")
        self.fixtexbtn.setMinimumSize(QtCore.QSize(x,y))

        btns = [self.incSavbtn,self.emailbtn,self.upldbtn,self.setPrjbtn,self.setPrjbtn,self.setThumb,self.shwMatbtn,self.fixtexbtn]

        [self.btnVLay.addWidget(each) for each in btns]


    def floatingToolBar(self):
        self.buttons()
        self.setLayout(self.btnVLay)


if __name__ =='__main__':
   import sys
   app = QtGui.QApplication(sys.argv)
   win = ToolBarUI()
   win.show()
   sys.exit(app.exec_())

but I have another UI in a different py file, to which I want to add the self.btnLay layout shown in code above

So far I have the mainUI file like this

import resources_rc1 as icons
import toolBarUI as toolBar
from PySide import QtGui,QtCore

class MyUI(QtGui.QMainWindow):
        def __init__(self,parent=getMayaWindow(),uniqueHandle="_PySide"):
                super(MyUI,self).__init__(parent)
                self.resize(600, 600)

                self.toolbar=toolBar.ToolBarUI()
                self.setObjectName(uniqueHandle)

                self.mainWidget = QtGui.QWidget(self)
                self.setCentralWidget(self.mainWidget)

                # some code here

                vbox_main = QtGui.QVBoxLayout()
                HBox3=QtGui.QHBoxLayout(self.mainWidget)
                VBox_AlwaysVisCont=QtGui.QVBoxLayout()
                VBox_AlwaysVisCont.addLayout(HBox1)
                VBox_AlwaysVisCont.addWidget(splitter_filelist)
                HBox3.addLayout(VBox_AlwaysVisCont)
                VBox_toolbar=QtGui.QVBoxLayout()
                self.toolbar.buttons()
                #VBox_toolbar.addLayout(self.btnLay)# this obviously gives error 
                vbox_main.addLayout(HBox3)

                #vbox_main.addLayout(HBox1)
                #vbox_main.addWidget(splitter_filelist)
                vbox_main.setContentsMargins(0,0,0,0)
                self.setLayout(HBox3)

So how should I call layout from a different method in different module ?

 
0
 

If you don't put a space around the equal signs, code is hard to read.
QMainWindows has its own layout management, read up on it!

 
0
 

Not sure if QMainWindow accepts absolute layout?

 
0
 

QMainWindow inherits the QWidget class so you shouldnt have a problem getting it to work

QMainWindow Documentation

Question Answered as of 1 Year Ago by vegaseat, Lardmeister, ZZucker and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article