# -*- 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学习之列表管理器(网友提供)的更多相关文章

  1. jmeter压测学习6-HTTP Cookie管理器

    前言 web网站的请求大部分都有cookies,jmeter的HTTP Cookie管理器可以很好的管理cookies. 我用的 jmeter5.1 版本,直接加一个HTTP Cookie管理器放到请 ...

  2. Jmeter压测学习5---HTTP Cookie管理器

    我司项目暂时不需要,直接转载:https://www.cnblogs.com/yoyoketang/p/11963342.html 前言 web网站的请求大部分都有cookies,jmeter的HTT ...

  3. Android布局管理器-从实例入手学习相对布局管理器的使用

    场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...

  4. com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: 为队列管理器提供的安全性认证无效

    com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: 为队列管理器“zm_queue_manager”提供的安全性认证无效, ...

  5. 【XLL 文档翻译】【第1部分】 Add-in 管理器 和 XLL 接口函数

    xlAddInManagerInfo/xlAddInManagerInfo12 在 Excel 会话中,每一次调用 Add-In 管理器时,系统会调用这两个函数.此函数可以在 Add-In 管理器中提 ...

  6. [置顶] Android布局管理器 - 详细解析布局实现

    布局管理器都是以ViewGroup为基类派生出来的; 使用布局管理器可以适配不同手机屏幕的分辨率,尺寸大小; 布局管理器之间的继承关系 : 在上面的UML图中可以看出, 绝对布局 帧布局 网格布局 相 ...

  7. 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现

    写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...

  8. <转>jmeter(十九)HTTP属性管理器

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...

  9. 跟我学Spring3(9.2):Spring的事务之事务管理器

    原文出处: 张开涛9.2.1 概述 Spring框架支持事务管理的核心是事务管理器抽象,对于不同的数据访问框架(如Hibernate)通过实现策略接口PlatformTransactionManage ...

随机推荐

  1. DB2 错误编码 查询(二)(转)

    DB2 SQLSTATE 讯息 类代码 42 语法错误或访问规则违例表 32. 类代码 42:语法错误或访问规则违例 SQLSTATE 值   含义 42501 授权标识不具有对标识对象执行指定操作的 ...

  2. [Typescript] Function defination

    Define a function type and params type: // The function init // Accept two params which are both typ ...

  3. Linux字符设备驱动file_operations

    struct _file_operations struct _file_operations在Fs.h这个文件里面被定义的,如下所示: struct file_operations { struct ...

  4. Pythn中的super用法

    在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如代码段1: 代码段1: 代码如下: class A: def __init__(self): p ...

  5. Velocity 语法示例

    一.简介: 1)它允许任何人使用简单而强大的模板语言来引用定义在 java 代码中的对象" 2)Velocity是一个基于java的模板引擎,简称VTL(Velocity Template ...

  6. 关于JS历史拓展

      js由来        95年那时,绝大多数因特网用户都使用速度仅为28.8kbit/s 的“猫”(调制解调器)上网,但网页的大小和复杂性却不断增加.为完成简单的表单验证而频繁地与服务器交换数据只 ...

  7. 安装XP和Ubuntu双系统问题——Ubuntu安装时无法识别原有系统

    我主机本来安装了windows xp 和unbuntu15.04,由于在ubuntu下不小心卸载某依赖后,无法登入桌面,网上查了好多资料,原因各种,解决途径也各种,最终是还没有解决问题.各种更新,各种 ...

  8. [c#]asp.net开发微信公众平台(5)微信图文消息

    上篇已经成功响应了关注事件,也实现了文本消息的发送,这篇开始图文消息处理, 微信中最常用的消息类型就是图文消息了,因为它图文并茂,最能表达信息. 图文消息在微信中的接口定义如下: <xml> ...

  9. ORACLE之SQL语句内部解析过程【weber出品】

    一.客户端通过监听连接到数据库,数据库开启一个server process进程来接收客户端传过来的sql. 1.这条sql语句从来都没有被执行过.(硬解析) 2.这条sql语句被执行过.(软解析) 二 ...

  10. Cookie 添加,读取,删除

    Name,value – 声明时 new Cookie(key,value); Path        - 默认值,即为当前保存cookie的这个serlvet所在的路径. 如果Cookie在这样的路 ...