pyqt学习之列表管理器(网友提供)
# -*- coding: utf-8 -*-
__author__ = 'Administrator'
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
MAC = "qt_mac_set_native_menubar" in dir()
class StringListDlg(QDialog):
def __init__(self, name, stringlist=None, parent=None):
super(StringListDlg, self).__init__(parent)
self.name = name
self.listWidget = QListWidget()
if stringlist is not None:
self.listWidget.addItems(stringlist)
self.listWidget.setCurrentRow(0)
buttonLayout = QVBoxLayout()
for text, slot in (("&Add...", self.add),
("&Edit...", self.edit),
("&Remove...", self.remove),
("&Up", self.up),
("&Down", self.down),
("&Sort", self.listWidget.sortItems),
("Close", self.accept)):
button = QPushButton(text)
if not MAC:
button.setFocusPolicy(Qt.NoFocus)
if text == "Close":
buttonLayout.addStretch()
buttonLayout.addWidget(button)
self.connect(button, SIGNAL("clicked()"), slot)
layout = QHBoxLayout()
layout.addWidget(self.listWidget)
layout.addLayout(buttonLayout)
self.setLayout(layout)
self.setWindowTitle("Edit %s List" % self.name)
def add(self):
row = self.listWidget.currentRow()
title = "Add %s" % self.name
string, ok = QInputDialog.getText(self, title, title)
if ok and not string.isEmpty():
self.listWidget.insertItem(row, string)
def edit(self):
row = self.listWidget.currentRow()
item = self.listWidget.item(row)
if item is not None:
title = "Edit %s" % self.name
string, ok = QInputDialog.getText(self, title, title,
QLineEdit.Normal, item.text())
if ok and not string.isEmpty():
item.setText(string)
def remove(self):
row = self.listWidget.currentRow()
item = self.listWidget.item(row)
if item is None:
return
reply = QMessageBox.question(self, "Remove %s" % self.name,
"Remove %s `%s'?" % (
self.name, unicode(item.text())),
QMessageBox.Yes|QMessageBox.No)
if reply == QMessageBox.Yes:
item = self.listWidget.takeItem(row)
del item
def up(self):
row = self.listWidget.currentRow()
if row >= 1:
item = self.listWidget.takeItem(row)
self.listWidget.insertItem(row - 1, item)
self.listWidget.setCurrentItem(item)
def down(self):
row = self.listWidget.currentRow()
if row < self.listWidget.count() - 1:
item = self.listWidget.takeItem(row)
self.listWidget.insertItem(row + 1, item)
self.listWidget.setCurrentItem(item)
def reject(self):
self.accept()
def accept(self):
self.stringlist = QStringList()
for row in range(self.listWidget.count()):
self.stringlist.append(self.listWidget.item(row).text())
self.emit(SIGNAL("acceptedList(QStringList)"), self.stringlist)
QDialog.accept(self)
if __name__ == "__main__":
fruit = ["Banana", "Apple", "Elderberry", "Clementine", "Fig",
"Guava", "Mango", "Honeydew Melon", "Date", "Watermelon",
"Tangerine", "Ugli Fruit", "Juniperberry", "Kiwi",
"Lemon", "Nectarine", "Plum", "Raspberry", "Strawberry",
"Orange"]
app = QApplication(sys.argv)
form = StringListDlg("Fruit", fruit)
form.exec_()
print "\n".join([unicode(x) for x in form.stringlist])
如图:
pyqt学习之列表管理器(网友提供)的更多相关文章
- jmeter压测学习6-HTTP Cookie管理器
前言 web网站的请求大部分都有cookies,jmeter的HTTP Cookie管理器可以很好的管理cookies. 我用的 jmeter5.1 版本,直接加一个HTTP Cookie管理器放到请 ...
- Jmeter压测学习5---HTTP Cookie管理器
我司项目暂时不需要,直接转载:https://www.cnblogs.com/yoyoketang/p/11963342.html 前言 web网站的请求大部分都有cookies,jmeter的HTT ...
- Android布局管理器-从实例入手学习相对布局管理器的使用
场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...
- com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: 为队列管理器提供的安全性认证无效
com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: 为队列管理器“zm_queue_manager”提供的安全性认证无效, ...
- 【XLL 文档翻译】【第1部分】 Add-in 管理器 和 XLL 接口函数
xlAddInManagerInfo/xlAddInManagerInfo12 在 Excel 会话中,每一次调用 Add-In 管理器时,系统会调用这两个函数.此函数可以在 Add-In 管理器中提 ...
- [置顶] Android布局管理器 - 详细解析布局实现
布局管理器都是以ViewGroup为基类派生出来的; 使用布局管理器可以适配不同手机屏幕的分辨率,尺寸大小; 布局管理器之间的继承关系 : 在上面的UML图中可以看出, 绝对布局 帧布局 网格布局 相 ...
- 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现
写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...
- <转>jmeter(十九)HTTP属性管理器
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...
- 跟我学Spring3(9.2):Spring的事务之事务管理器
原文出处: 张开涛9.2.1 概述 Spring框架支持事务管理的核心是事务管理器抽象,对于不同的数据访问框架(如Hibernate)通过实现策略接口PlatformTransactionManage ...
随机推荐
- 【HPP开发】让所有中小企业拥有自己的APP
HPP hybirdApp或者hbuilderApp, 指通过html,css,js语言开发出ios和android两个版本的APP, 开发效率成倍上升,开发时间大幅缩减,开发成本同样也大大缩减. 移 ...
- [React Testing] Element types with Shallow Rendering
When you render a component with the Shallow Renderer, you have access to the underlying object. We ...
- 网页HTML
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- Js 插件修改及优化总结
1. ajaxfileupload 上传插件版本问题以及数据处理问题 参考链接: http://liwx2000.iteye.com/blog/1540321 现在大家至少也在用jquery1.9以上 ...
- web离线应用
其实浏览器一直都是前端开发人员比较头痛的一个课题,各种兼容性.直到开始规范化和标准化,HTML5的出现. 在没有这套标准出现之前,对于客户端缓存的问题,我们基本上都是用cookie处理,当然目前除了后 ...
- CF 277E Binary Tree on Plane (拆点 + 费用流) (KM也可做)
题目大意: 平面上有n个点,两两不同.现在给出二叉树的定义,要求树边一定是从上指向下,即从y坐标大的点指向小的点,并且每个结点至多有两个儿子.现在让你求给出的这些点是否能构成一棵二叉树,如果能,使二叉 ...
- 《Hadoop权威》学习笔记五:MapReduce应用程序
一.API的配置---Configuration类 API的配置:Hadoop提供了专门的API对资源进行配置,Configuration类的实例(在org.apache.hadoop.conf包)包 ...
- 汇编语言中PTR的含义(转载)
mov ax,bx ;是把BX寄存器“里”的值赋予AX,由于二者都是word型,所以没有必要加“WORD” mov ax,word ptr [bx];是把内存地址等于“BX寄存器的值”的地方所存放的数 ...
- php时间戳与时间转换
PHP时间大的来分有两种,一是时间戳类型(1228348800),二是正常日期格式(2008-12-4) 所以存到数据库也有两种形式了(真正不止,我的应用就两种),时间戳类型我是保存为字符串的,这个是 ...
- nodejs个人配置
国内镜像,飞一般的感觉!编辑 ~/.npmrc 加入下面内容 registry = http://registry.cnpmjs.org npm config set registry http:/ ...