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反向解析导致连接缓慢
Content 0.序 1.问题 2.原因 3.解决办法 0.序 本文主要是记录Mysql安装在 VMWARE下,本地连接Mysql速度很慢的原因及解决办法. 1.问题 本地的一个网站使用mysql数 ...
- js中什么是对象,对象的概念是什么?
我们一直在用对象 可是你真的理解对象吗,js中有一个说法是一切皆对象,其实这里说的应该是 一切皆可看作对象 对象就是可以拥有属性和方法的一个集合 士兵就是一个对象,它拥有身高体重的属性,保家卫国,吃饭 ...
- How to exit the entire application from a Python thread?
If all your threads except the main ones are daemons, the best approach is generally thread.interrup ...
- Solution for sending Whatsapp via sqlite "INSERT INTO"
I use something similar but thought I'd mention this 'bug' that can happen:when you INSERT '%wa_mess ...
- LINUX mysql 源码安装
一.下载编译安装 #cd /usr/local/src/ #wget http://mysql.byungsoo.net/Downloads/MySQL-5.1/mysql-5.1.38.tar.gz ...
- Geeks 一般二叉树的LCA
不是BST,那么搜索两节点的LCA就复杂点了,由于节点是无序的. 以下是两种方法,都写进一个类里面了. 当然须要反复搜索的时候.能够使用多种方法加速搜索. #include <iostream& ...
- winform打开进程与关闭进程
#region 判断某进程名是否运行 /// <summary> /// 关闭指定名称的进程 /// </summary> /// <param name="p ...
- 使用jQuery异步传递含复杂属性及集合属性的Model到控制器方法
Student类有集合属性Courses,如何把Student连同集合属性Courses传递给控制器方法? public class Student { public ...
- Python 必备神器
1. pip 用来包管理 文档:https://pip.pypa.io/en/latest/installing.html # 安装,可指定版本号(sudo) pip install Django== ...
- CMMI5级——原因分析及解决方案(Causal Analysis and Resolution)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010825142/article/details/15338085 聪明的人在出现问题的时候,除了 ...