We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,613 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

window showing up empty

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 ?

3
Contributors
6
Replies
15 Hours
Discussion Span
4 Months Ago
Last Updated
7
Views
krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Replace
QtGui.QMainWindow
with
QtGui.QWidget

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

vegaseat
DaniWeb's Hypocrite
Moderator
6,464 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,608
Skill Endorsements: 34

why i cannot use QMainWindow though ?

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

vegaseat
DaniWeb's Hypocrite
Moderator
6,464 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,608
Skill Endorsements: 34

so how to instead add widgets to its default layout?

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

Lardmeister
Posting Virtuoso
1,938 posts since Mar 2007
Reputation Points: 465
Solved Threads: 72
Skill Endorsements: 5

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

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0741 seconds using 2.69MB