Menubar
A menubar is a common part of a GUI application. It is a group of commands located in various menus.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This program creates a menubar. The
menubar has one menu with an exit action. author: Jan Bodnar
website: zetcode.com
last edited: August 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QMainWindow): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(QtGui.qApp.quit) self.statusBar() menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction) self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menubar')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
In the above example, we create a menubar with one menu. This menu contains one action which terminates the application if selected. A statusbar is created as well. The action is accessible with theCtrl+Q shortcut.
exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
A QtGui.QAction is an abstraction for actions performed with a menubar, toolbar or with a custom keyboard shortcut. In the above three lines, we create an action with a specific icon and an 'Exit' label. Furthermore, a shortcut is defined for this action. The third line creates a status tip which is shown in the statusbar when we hover a mouse pointer over the menu item.
exitAction.triggered.connect(QtGui.qApp.quit)
When we select this particular action, a triggered signal is emitted. The signal is connected to thequit() method of the QtGui.QApplication widget. This terminates the application.
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
The menuBar() method creates a menubar. We create a file menu and append the exit action to it.
Menubar的更多相关文章
- 【Windows编程】系列第七篇:Menubar的创建和使用
上一篇我们学习了利用windows API创建工具栏和菜单栏,与上一篇紧密联系的就是菜单栏,菜单栏是一个大多数复杂一些的Windows应用程序不可或缺的部分.比如下图就是Windows自带的记事本的菜 ...
- “菜单”(menubar)和“工具栏”(toolbars)
"菜单"(menubar)和"工具栏"(toolbars) "菜单" (menubar)和"工具栏"(toolbars) ...
- flashbuilder mx组件 MenuBar
来源:http://www.cuplayer.com/player/PlayerCode/Flex/2013/0118661.html <fx:Script> <![CDATA[ i ...
- 3.关于QT中的MainWindow窗口,MenuBar,ToolBar,QuickTip等方面的知识点
1 新建一个空Qt项目 编写12MainWindow.pro HEADERS += \ MyMainWindow.h \ MyView.h SOURCES += \ MyMainWindow.c ...
- WorldWind源码剖析系列:图层管理器按钮类LayerManagerButton和菜单条类MenuBar
WorldWindow用户定制控件类中所包含的的可视化子控件主要有:图层管理器按钮类LayerManagerButton和菜单条类MenuBar.BmngLoader类中所包含的的可视化子控件主要有: ...
- Texas Instruments matrix-gui-2.0 hacking -- menubar.php
<?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...
- Statusbar、Menubar、Toolbar合集
In the last example of this section, we create a menubar, a toolbar and a statusbar. We also create ...
- Flex4以后Menubar背景设置问题
flex4的 backgroundColor失效,需要使用 contentBackgroundColor menubar.setStyle("contentBackgroundColor&q ...
- 零元学Expression Blend 4 - Chapter 44 Flash做的到的Blend也可以!轻松制作拥有动画的MenuBar!(下)
原文:零元学Expression Blend 4 - Chapter 44 Flash做的到的Blend也可以!轻松制作拥有动画的MenuBar!(下) 抱歉久等了!!!! 终於到了动画MenuBar ...
随机推荐
- mysql---总体备份和增量备份
总体备份: 对整张表或者整个数据库甚至全部数据库进行备份. 增量备份: 对某一范围内的数据进行备份. 1.总体备份: 对表进行备份: 针对存储引擎为myisam的表,能够直接复制frm.myd.myi ...
- python性能优化建议
参考: https://segmentfault.com/a/1190000000666603 http://blog.csdn.net/zhoudaxia/article/details/23853 ...
- 关于linux系统端口查看和占用的解决方案
原文:http://www.2cto.com/os/201411/355959.html 一直以来,在处理linux服务器的过程中,经常会遇到一个问题,有时候kill掉进程之后,端口被占用,新的进程一 ...
- Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution
Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ix ...
- 为iOS应用制作一个二维码
第一步:找到你发布的ios应用的下载链接: 第二步:使用二维码转换器,将下载链接转换成 二维码.http://my.qzone.qq.com/app/100699951.html?via=appcen ...
- C#编程(六)------------枚举
原文链接:http://blog.csdn.net/shanyongxu/article/details/46423255 枚举 定义枚举用到的关键字:enum public enum TimeOfD ...
- JAVA基础知识要点
MQ.dubbo.SpringCloud 1) 集合框架 2)线程 3)IO流 4)类和对象生命周期 5)JAVA的反射机制 6) JVM 7)数据结构和常用算法 8)设计模式 9)网络编程
- Java中List效率的比较
Java Collections Framework(JCF) 是Java SE中一个基本的类集,几乎所有的项目都会用到,其中的List 则是JCF中最最常用的一个接口.围绕List 接口,有很多实现 ...
- 收藏的iOS技术站点汇总(持续更新ing)
大牛博客 objc.io PS:经典,内容深而广 objc中国 NSHipster PS:非常多小细节 NSHipster 中文版 唐巧的技术博客 PS:LZ是唐巧的脑残粉- OneV's Den 王 ...
- Java集合框架2
8. 枚举(Enum)使用示例 声明一个枚举类型的简单形式如下: 访问类型 enum 枚举类名{值1[,值2,......]}; 例8. 为枚举类添加辅助方法. package set; public ...