You kinda got it: you only need to lambda the slot if you want to pass an argument, otherwise you just pass a reference to the slot. The following is your example corrected as necessary:
@
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def init(self):
super(Window, self).init()
self.initUI()
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def initUI(self):
edit = QtGui.QTextEdit(self)
edit.setStatusTip('Input Text Here')
edit.setToolTip('Input Text Here')
self.setCentralWidget(edit)
exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit Application')
exitAction.triggered.connect(QtGui.qApp.quit)
copyAction = QtGui.QAction(QtGui.QIcon('copy.png'), '&Copy', self)
copyAction.setShortcut('Ctrl+C')
copyAction.setStatusTip('Copy to the Clipboard')
copyAction.triggered.connect(edit.copy)
pasteAction = QtGui.QAction(QtGui.QIcon('paste.png'), '&Paste', self)
pasteAction.setShortcut('Ctrl+V')
pasteAction.setStatusTip('Paste from the Clipboard')
pasteAction.triggered.connect(edit.paste)
cutAction = QtGui.QAction(QtGui.QIcon('cut.png'), '&Cut', self)
cutAction.setShortcut('Ctrl+X')
cutAction.setStatusTip('Copy text to the clipboard and delet from editor')
cutAction.triggered.connect(edit.cut)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
editMenu = menubar.addMenu('&Edit')
editMenu.addAction(copyAction)
editMenu.addAction(pasteAction)
editMenu.addAction(cutAction)
toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
toolbar.addAction(copyAction)
toolbar.addAction(pasteAction)
toolbar.addAction(cutAction)
self.setGeometry(10, 10, 500, 500)
self.setWindowTitle('Text Editor')
self.setWindowIcon(QtGui.QIcon('favicon.png'))
self.center()
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(
self,
'Message',
"Are you sure you would like to quit?",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No
)
if reply == QtGui.QMessageBox.Yes: event.accept()
else: event.ignore()
if name == 'main':
import sys
app = QtGui.QApplication(sys.argv)
ex = Window()
ex.show()
ex.raise_()
sys.exit(app.exec_())
@