试图自学PyQt5,所以我想我没有在添加一些东西。但是我目前在窗口顶部有一个菜单栏,想在下面添加一个框架,但是这样做会使菜单酒吧无法进入。没有框架,菜单栏就可以正常工作。我该如何解决?
wxEVT_SIZE
答案 0 :(得分:0)
QMainWindow.setCentralWidget(小部件)
将给定的小部件设置为主窗口的中央小部件。
import sys
from PyQt5.QtWidgets import (QMainWindow, QApplication, QFrame, QAction, qApp,
QStackedWidget, QWidget, QListWidget, QVBoxLayout)
from PyQt5.QtGui import QIcon
class CharManMain(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
'''initiates application UI'''
exitAct = QAction('&Exit', self)
exitAct.setShortcut('Ctrl+Q')
exitAct.setStatusTip('Exit Application')
exitAct.triggered.connect(qApp.quit)
newAct = QAction('&New', self)
newAct.setShortcut('Ctrl+N')
newAct.setStatusTip('Create a New character')
openAct = QAction('&Open', self)
openAct.setShortcut('Ctrl+O')
openAct.setStatusTip('Open a saved character')
statusbar = self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
characterMenu = menubar.addMenu('Characters')
fileMenu.addAction(newAct)
fileMenu.addAction(openAct)
fileMenu.addAction(exitAct)
baseFrame = QFrame() # --- (self)
self.setCentralWidget(baseFrame) # +++ <-----
### ---
#vbox = QVBoxLayout()
#vbox.addWidget(menubar)
#vbox.addWidget(baseFrame)
#vbox.addWidget(statusbar)
#self.setLayout(vbox)
self.setWindowTitle('Character Manager v0.01')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
charMain = CharManMain()
sys.exit(app.exec_())