On Oct 22, 2009, at 10:57 AM, Baz Walter wrote:
I'm using addAction to add the action to the app's main menu. See simple, running code sample attached. Note line 59. The action's first arg is misspelled "Setttings." Using the correct spelling, the action silently fails to be added to the menu. Thanks Scott |
#!/usr/bin/env python import sys from PyQt4 import QtCore, QtGui
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
w = QtGui.QWidget()
self.setCentralWidget(w)
topFiller = QtGui.QWidget()
topFiller.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.infoLabel = QtGui.QLabel(self.tr("<i>see File menu</i>"))
self.infoLabel.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken)
self.infoLabel.setAlignment(QtCore.Qt.AlignCenter)
bottomFiller = QtGui.QWidget()
bottomFiller.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
vbox = QtGui.QVBoxLayout()
vbox.setMargin(5)
vbox.addWidget(topFiller)
vbox.addWidget(self.infoLabel)
vbox.addWidget(bottomFiller)
w.setLayout(vbox)
self.createActions()
self.createMenus()
self.setWindowTitle(self.tr("Menu Test"))
self.setMinimumSize(160,160)
self.resize(480,320)
def settingsEdit(self):
print "settingsEdit() ..."
def newFile(self):
self.infoLabel.setText(self.tr("Invoked <b>File|New</b>"))
def createActions(self):
self.newAct = QtGui.QAction(self.tr("&New"), self)
self.newAct.setShortcut(self.tr("Ctrl+N"))
self.newAct.setStatusTip(self.tr("Create a new file"))
self.connect(self.newAct, QtCore.SIGNAL("triggered()"), self.newFile)
self.exitAct = QtGui.QAction(self.tr("E&xit"), self)
self.exitAct.setShortcut(self.tr("Ctrl+Q"))
self.exitAct.setStatusTip(self.tr("Exit the application"))
self.connect(self.exitAct, QtCore.SIGNAL("triggered()"), self.close)
self.settingsEditAct = QtGui.QAction(self.tr("Setttings..."), self) # note misspelling
self.settingsEditAct.setStatusTip(self.tr("Settings Form..."))
self.settingsEditAct.setShortcut(self.tr("Ctrl+E"))
self.connect(self.settingsEditAct, QtCore.SIGNAL("triggered()"), self.settingsEdit)
def createMenus(self):
self.fileMenu = self.menuBar().addMenu(self.tr("&File"))
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.exitAct)
self.fileMenu.addAction(self.settingsEditAct)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec_())
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
