1.11M Members

window showing up empty

 
0
 
from PySide import QtCore,QtGui
import sys
class ToolBarUI(QtGui.QMainWindow):
    def __init__(self,*args,**kwargs):
        super(ToolBarUI,self).__init__(*args,**kwargs)
        self.floatingToolBar()
        pass

    def buttons(self):
        self.btnVLay=QtGui.QVBoxLayout()
        self.incSavbtn=QtGui.QPushButton("Save")
        self.emailbtn=QtGui.QPushButton("Email")
        self.upldbtn=QtGui.QPushButton("Upload")
        self.setPrjbtn=QtGui.QPushButton("Set Project")
        self.setThumb=QtGui.QPushButton("Set thumb")
        self.shwMatbtn=QtGui.QPushButton("Show Material")
        self.fixtexbtn=QtGui.QPushButton("Fix Texture Paths")

        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)
        self.show()
        pass

if __name__ =='__main__':

    app = QtGui.QApplication(sys.argv)
    app.setStyle("cleanlooks")
    win = ToolBarUI()
    win.floatingToolBar()
    sys.exit(app.exec_())

why the above code is showing an empty window , I am trying to stack buttons in VBoxLayout()..
any idea what am i forgetting ?

 
1
 

Replace
QtGui.QMainWindow
with
QtGui.QWidget

also comment out
win.floatingToolBar()
or you will be calling it twice

 
0
 

why i cannot use QMainWindow though ?

 
1
 

QMainWindow has its own layout manager to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar. The layout has a center area that can be occupied by any kind of widget. Layouts like QVBoxLayout() won't work.

 
0
 

so how to instead add widgets to its default layout?

 
1
 

You could add a QWidget to its center area and then go on with the familiar layouts in that widget. Kind of cumbersome. Might as well go with Qwidget rigth away.

 
0
 

So i have made the following changes , i am stuck at adding context menu on left click over a button not the right click

from PySide import QtCore,QtGui
import sys
class ToolBarUI(QtGui.QWidget):
    def __init__(self,*args,**kwargs):
        super(ToolBarUI,self).__init__(*args,**kwargs)
        self.createActions()

        self.floatingToolBar()
        pass

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

    def buttons(self):
        x,y=15,35
        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.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 contextMenuEvent(self, event):
        menu = QtGui.QMenu(self)
        menu.addAction(self.emlSel)
        menu.addAction(self.emlScn)
        menu.addAction(self.emlBufr)
        #menu.exec_(self.emailbtn.mapToGlobal(QtCore.QPoint(0,0)))
        #menu.exec_(event.globalPos())

    def createActions(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)


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

if __name__ =='__main__':

    app = QtGui.QApplication(sys.argv)

    win = ToolBarUI()
    win.show()
    sys.exit(app.exec_())

I have commented out how i was trying in the contextMenuEvent method...
any idea how to make context menu work on left click over button, i have tried this way too..

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.connect(self.emailbtn, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menu)

but this totaly doesnt shows the menu maybe its pyqt4 approach, is slightly different from pyside

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: