1,105,450 Community Members

window showing up empty

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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 ?

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
1
 

Replace
QtGui.QMainWindow
with
QtGui.QWidget

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

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

why i cannot use QMainWindow though ?

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
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.

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

so how to instead add widgets to its default layout?

Member Avatar
Lardmeister
Posting Virtuoso
1,966 posts since Mar 2007
Reputation Points: 434 [?]
Q&As Helped to Solve: 111 [?]
Skill Endorsements: 8 [?]
 
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.

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: