QtGui.QComboBox
2024-08-27 00:01:26
The QtGui.QComboBox
is a widget that allows a user to choose from a list of options.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows
how to use QtGui.QComboBox widget. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.lbl = QtGui.QLabel("Ubuntu", self) combo = QtGui.QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Red Hat")
combo.addItem("Gentoo") combo.move(50, 50)
self.lbl.move(50, 150) combo.activated[str].connect(self.onActivated) self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QComboBox')
self.show() def onActivated(self, text): self.lbl.setText(text)
self.lbl.adjustSize() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
The example shows a QtGui.QComboBox
and a QtGui.QLabel
. The combo box has a list of five options. These are the names of Linux distros. The label widget displays the selected option from the combo box.
combo = QtGui.QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Red Hat")
combo.addItem("Gentoo")
We create a QtGui.QComboBox
widget with five options.
combo.activated[str].connect(self.onActivated)
Upon an item selection, we call the onActivated()
method.
def onActivated(self, text): self.lbl.setText(text)
self.lbl.adjustSize()
Inside the method, we set the text of the chosen item to the label widget. We adjust the size of the label.
Figure: QtGui.QComboBox
最新文章
- hibernate中一对多关系中的inverse,cascade属性
- Windows安装mxnet
- 安装 Dubbo 注册中心(Zookeeper-3.4.6)--单节点
- magento缓存系列详解:clean cache
- IIS6.0禁止用户下载txt文件
- 学习java随笔第十一篇:java窗体程序
- (中等) POJ 2528 Mayor's posters , 离散+线段树。
- Java数据结构和算法(十五)——无权无向图
- 面试作业之浅析京东促销活动核心模型 - DDD
- Python3 NameError: name 'open' is not defined处理办法
- SpringBoot aop 注解 数据权限校验
- php 删除一维数组中某一个值元素的操作方法
- Linux学习系列之一:在centos 7.5上安装nginx 以及简单配置
- 【转】25个非常实用的jQuery/CSS3应用组件
- ASP.NET Web Pages:C# 和 VB 实例
- Ansible playbook基础组件介绍
- Java之MD5加密
- LR-事务
- Uncaught TypeError: Cannot set property 'value' of null
- Generator 函数的异步应用
热门文章
- serializable parcelable
- Codeforces Beta Round #7 C. Line Exgcd
- Educational Codeforces Round 10 C. Foe Pairs 水题
- js中进行金额计算 parseFloat 会产生精度问题
- KVM虚拟机安装使用教程(Ubantu)
- UVA1493 - Draw a Mess(并查集)
- Spring内部bean实例
- JavaScript中typeof详解
- 【spring boot】整合LCN,启动spring boot2.0.3 启动报错:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
- WebLogic中WLS 组件漏洞(CVE-2017-10271)专项检测工具