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

QtGui.QComboBox的更多相关文章

  1. Pyqt QComboBox 省市区县联动效果

    在Qt中, QComboBox方法窗口组件允许用户从列表清单中选择,在web中就是select标签,下拉选项. 省市区县的联动就是currentIndexChanged 获取当前的Index,通过这个 ...

  2. Pyqt Smtplib实现Qthread多线程发送邮件

    一. smtplib 的介绍 smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])   SMTP类构造函数,表示与SMTP服务器之间的连接 ...

  3. Pyqt QSystemTrayIcon 实现托盘效果

    pyqt的托盘效果很好实现,在Pyqt的demo中有个例子 路径:PyQt4\examples\desktop\systray.py 今天我就仿这个Tray效果做效果 一. 创建UI trayicon ...

  4. Qt4升级Qt5注意问题

    Qt4升级Qt5注意问题 Qt4过渡到Qt5的项目一开始就受阻,记录一下遇到的下面的问题 --->编译遇到类似错误: error: QCalendarWidget: No such file o ...

  5. pyqt记录内容(音乐播放器)

    #这是UI文件 # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'AudioPlayerDia ...

  6. PYQT4 : QSystemTrayIcon练习

    照着demo自己做了一遍,练练手 import sys from PyQt4 import QtGui from PyQt4 import QtCore class SysTray(QtGui.QDi ...

  7. pyqt4_应用例子(计算器,对话框,进度条,日历等等)

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  8. PYQT控件使用

    QtGui.QComboBox .addItem(string)#添加字符串项到Item.addItems(list)#添加列表或元组元素到Item.clear()#清除所有Item.clearEdi ...

  9. ZetCode PyQt4 tutorial widgets II

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

随机推荐

  1. nginx fastcgi_buffers to an upstream response is buffered to a temporary file

    fastcgi_buffers 16 16k; 指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答,如上所示,如果一个php脚本所产生的页面大小为256k,则会为其分配16个16k的缓冲区来缓 ...

  2. Dubbo整合SpringCloud图片显示问题

    Dubbo整合SpringCloud图片显示问题 Tips:公司项目,记录一点经验吧,理解的不对的地方欢迎大神指点 问题:商品图片上传功能(公司没有专门文件服务器)写的保存目录直接是保存在docker ...

  3. 装饰者模式:轻松记住IO类的关系与API

    开门见山 目录 概述与模型 1.概述 含义:动态地将责任附加到对象上.若要拓展功能,装饰者提供了比继承更有弹性的替代方案. 初衷:需要动态为某一个类拓展.通常我们会使用继承,但是继承的话,会产生很多子 ...

  4. undefined null 各种值比较(面试题)

    undefined和null与任何有意义的值比较返回的都是false,但是null与undefined之间互相比较返回的是true. console.log(null == false); //fal ...

  5. CentOS 6.9/7通过yum安装指定版本的Node.js

    说明:通过yum好处其实很多,环境变量不用配置,配置文件放在大家都熟悉的地方,通过rpm -ql xxx可以知道全部文件的地方等等. Node.js(8.x) 一.安装和配置 1.安装Node.js ...

  6. 解决数据库 Table 'content_tags' is marked as crashed and should be repaired 表损坏问题

    今天突然网站TAG页面打不开了,打开debug,发现提示 Table 'content_tags' is marked as crashed and should be repaired 这样的错误 ...

  7. 移动应用安全开发指南(Android)--数据验证

    概述 移动应用往往通过数据的发送.接收和处理来完成一系列功能,通常情况下,处理的数据绝大部分都来源于外部(比如网络.内部或外部存储和用户输入等),对这些数据处理不当会导致各种各样的漏洞和风险,比代码执 ...

  8. PSCollectionView瀑布流实现

    [-] 一基本原理 二具体实现 相关数据结构 视图更新方式 relayoutViews方法 removeAndAddCellsIfNecessary方法 select方法 重用数据块视图机制 三使用方 ...

  9. eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi

    下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...

  10. 获取android-5.0.2_r1代码6.7G

    获取 android-5.0.2_r1 源代码的坎坷路: 服务器相关 ====== * 国外服务器直接拉取,我一共有多个国外服务器,在获取android代码时下载速度都能到10MB/s的下载速度甚至更 ...