On Oct 22, 2009, at 10:57 AM, Baz Walter wrote:

Scott Frankel wrote:
Does a QMainWindow, or an app based on, one contain a list of default action names?
I'm trying to add an action called "Settings" to my app.  The addAction() method silently fails unless I rename or misspell the action, like "Foo" or "Setttings."
Actions named "Settings", "Preferences", "Configuration" all silently fail.
Trying to find what names may already be claimed, my invocations of the actions() method always return an empty list.

it would help if you posted a complete example that demonstrates the problem. the above code snippet doesn't show the action being added to anything. are you trying add actions to a menu in the menubar, or are you trying to create a context menu?



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

Reply via email to