2
我已经开始从example of Zetcode学习PySide并尝试代码应用程序,它有两个窗口打开:“图解视图”,这是“布局视图”父母,每个菜单酒吧。在开始时应该只是示意图窗口,并且布局win应该通过菜单栏的根目录switchtoLAYOUT启动。PySide如何将焦点设置到新的窗口,如果不存在
我的问题是:
- 如何使“switchtoLAYOUT”根不显示下拉列表,并仍然在做动作只有一个“布局视图”窗口的实例?
- 如何切换两个窗口(“switchtoLAYOUT”和“switchtoSCHEMATIC”)之间的重点是什么?
- 请检查我的代码,并建议我的东西智能(即不应该不难)。
验证码:
import sys
from PySide import QtCore, QtGui
class schematicWindow(QtGui.QMainWindow):
def __init__(self):
super(schematicWindow, self).__init__()
self.defineSchWin()
def defineSchWin(self):
exitAction = QtGui.QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
menubar.addMenu('&Edit')
menubar.addMenu('&Passives')
menubar.addMenu('&Descretes')
menubar.addMenu('&IC\'s')
swToLayMenu = menubar.addMenu('switchtoLAYOUT')
swToLayAction = QtGui.QAction(self)
swToLayAction.triggered.connect(self.layoutWindow)
swToLayMenu.addAction(swToLayAction) # open layoutWindow (if not exists)
# and set focus to layoutWindow
self.setGeometry(0, 300, 500, 300)
self.setWindowTitle('Schematic View')
self.show()
def layoutWindow(self):
window = QtGui.QMainWindow(self)
window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
window.statusBar()
menubar = window.menuBar()
switchtoSchMenu = menubar.addMenu('switchtoSCHEMATIC')
window.setGeometry(100, 600, 500, 300)
window.setWindowTitle('Layout View')
window.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = schematicWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
责任。只需要更改为.raise_()并且它可以工作。你能帮助我如何点击“switchtoLAYOUT”而不必删除空的子菜单吗? – Alex
我不明白你的问题。 – tacaswell
如果我不清楚,请打扰一下。如果您单击“文件”它拉下来文件选项的子菜单,但“switchtoLAYOUT”没有选择,我想点击它立即做一个动作,不要拉下子菜单。 – Alex