We will create a menu bar, a toolbar, a status bar, and a central part.
#!/usr/bin/python#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui, QtcoreclassMainWindow (Qtgui.qmainwindow):def __init__(Self, parent =None): Qtgui.qmainwindow.__init__(self) self.resize (350, 250) Self.setwindowtitle ('main Window') TextEdit=Qtgui.qtextedit () self.setcentralwidget (textEdit) Exit= Qtgui.qaction (Qtgui.qicon ('Exit.png'),'Exit', self) exit.setshortcut ('Ctrl+q') Exit.setstatustip ('Exit Application') Self.connect (Exit, Qtcore.signal ('triggered ()'), Qtgui.qapp, Qtcore.slot ('quit ()') ) Self.statusbar () MenuBar=self.menubar () file= Menubar.addmenu ('&file') file.addaction (exit) Self.toolbar= Self.addtoolbar ('Exit') self.toolbar.addAction (exit) app=qtgui.qapplication (SYS.ARGV) main=MainWindow () main.show () Sys.exit (App.exec_ ())
Effect:
In this example, we created a text-editing part and set it as the central part of the Qmainwindow. The center part will occupy all the remaining space in the window.
PYQT4 Menu bar + toolbar + status bar + Center part to generate a text editing piece example