#!/usr/bin/env python

#-*- coding:utf-8 -*-

import sip

sip.setapi('QString', 2)

sip.setapi('QVariant', 2)

from PyQt4 import QtCore, QtGui

class MyWindow(QtGui.QWidget):

def __init__(self, parent=None):

super(MyWindow, self).__init__(parent)

self.pathRoot = QtCore.QDir.rootPath()

self.model = QtGui.QFileSystemModel(self)

self.model.setRootPath(self.pathRoot)

self.indexRoot = self.model.index(self.model.rootPath())

self.treeView = QtGui.QTreeView(self)

self.treeView.setModel(self.model)

self.treeView.setRootIndex(self.indexRoot)

self.treeView.clicked.connect(self.on_treeView_clicked)

self.labelFileName = QtGui.QLabel(self)

self.labelFileName.setText("File Name:")

self.lineEditFileName = QtGui.QLineEdit(self)

self.labelFilePath = QtGui.QLabel(self)

self.labelFilePath.setText("File Path:")

self.lineEditFilePath = QtGui.QLineEdit(self)

self.gridLayout = QtGui.QGridLayout()

self.gridLayout.addWidget(self.labelFileName, 0, 0)

self.gridLayout.addWidget(self.lineEditFileName, 0, 1)

self.gridLayout.addWidget(self.labelFilePath, 1, 0)

self.gridLayout.addWidget(self.lineEditFilePath, 1, 1)

self.layout = QtGui.QVBoxLayout(self)

self.layout.addLayout(self.gridLayout)

self.layout.addWidget(self.treeView)

@QtCore.pyqtSlot(QtCore.QModelIndex)

def on_treeView_clicked(self, index):

indexItem = self.model.index(index.row(), 0, index.parent())

fileName = self.model.fileName(indexItem)

filePath = self.model.filePath(indexItem)

self.lineEditFileName.setText(fileName)

self.lineEditFilePath.setText(filePath)

if __name__ == "__main__":

import sys

app = QtGui.QApplication(sys.argv)

app.setApplicationName('MyWindow')

main = MyWindow()

main.resize(666, 333)

main.move(app.desktop().screen().rect().center() - main.rect().center())

main.show()

sys.exit(app.exec_())

pyqt例子搜索文本的更多相关文章

  1. whoosh----索引|搜索文本类库

    先了解基本概念和步骤: Quick Start Whoosh是一个索引文本和搜索文本的类库,他可以为你提供搜索文本的服务,比如如果你在创建一个博客的软件,你可以用whoosh为它添加添加一个搜索功能以 ...

  2. C#编程实现Excel文档中搜索文本

    有了在Word文档中编程实现搜索文本的经验,在Excel中实现这个功能也并非难事. 打开Excel的VBA帮助,查看Excel的对象模型,很容易找到完成这个功能需要的几个集合和对象:Applicati ...

  3. 【Python自然语言处理】第一章学习笔记——搜索文本、计数统计和字符串链表

    这本书主要是基于Python和一个自然语言工具包(Natural Language Toolkit, NLTK)的开源库进行讲解 NLTK 介绍:NLTK是一个构建Python程序以处理人类语言数据的 ...

  4. JQuery+AJAX实现搜索文本框的输入提示功能

    平时使用谷歌搜索的时候发现只要在文本框里输入部分单词或字母,下面马上会弹出一个相关信息的内容框可供选择.感觉这个功能有较好的用户体验,所以也想在自己的网站上加上这种输入提示框. 实现的原理其实很简单, ...

  5. grep搜索文本

    正则匹配: grep -E "[a-z]+" 只输出匹配到的文本: echo this is a line. | grep -o -E "[a-z]+\." 统 ...

  6. css 样式设计(一)( 在线150个例子 | 背景 | 文本 | 字体 | 链接 | 列表 | 表格 | 盒模型 | 边框 | 轮廓 | 边距 | 填充 |分组和嵌套 | 尺寸 | 定位 | 浮动 |对齐 )

    一.css在线150个例子 http://www.w3cschool.cc/css/css-examples.html 二.背景图片水平方向重复 : body { background-image:u ...

  7. Linux 命令 - grep: 正则搜索文本

    grep 搜索文本文件中与指定正则表达式匹配的行 命令格式 grep [OPTIONS] PATTERN [FILE...] 命令参数 Generic Program Information --he ...

  8. vi下搜索文本

    ) /user ) n 下一个匹配 ) N 上一个匹配 ) ?user 从结尾开始搜索 ) :nohlsearch 关闭高亮显示6) :100 跳转到第100行

  9. linux 搜索文本

    find -type f -name '*.php'|xargs grep '127.0.0.1'  搜索所有.php 内容 127.0.0.1 转自:http://www.cnblogs.com/w ...

随机推荐

  1. [ES6] Rest Parameter

    Problem with the ES5: function displayTags(){ for (let i in arguments) { let tag = arguments[i]; _ad ...

  2. speex的基本编码和解码流程

    最近在研究speex的编码和解码流程 之前在IM上用到的都是发语音片段,这个很简单,只需要找到googlecode上gauss的代码,然后套一下就可以用了. 不过googlecode要关闭,有人将他导 ...

  3. 通知 Notification 详解

    效果 通知栏-刚收到通知时 通知栏-收到通知几秒后 标准视图 大视图-下滑前是标准视图 大视图-下滑后显示大视图 自定义通知 讲解 Notification,俗称通知,是一种具有全局效果的通知,它展示 ...

  4. Tree( 树) 组件[3]

    本节课重点了解 EasyUI 中 Tree(树)组件的使用方法, 这个组件依赖于 Draggable(拖动)和 Droppable(放置)组件.一. 事件列表很多事件的回调函数都包含'node'参数, ...

  5. 使用SQL语句创建和删除约束

    原文:http://blog.csdn.net/hamber_bao/article/details/6504905 约束的目的就是确保表中的数据的完整性. 常用的约束类型如下: 主键约束:(Prim ...

  6. android 自定义view之 TypeArray

    在定义view的时候,我们可以使用系统提供的属性,也可以自定义些额外的属性来设置自定义view的样式,这个时候,我们就需要TypeArray,字面意思就是Type 数组. 今天我们就讲讲如何自定义Vi ...

  7. Hadoop map reduce 任务数量优化

    mapred.tasktracker.map.tasks.maximum 官方解释:The maximum number of map tasks that will be run  simultan ...

  8. iOS在UITableViewController里使用UISearchDisplayController报错"[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:]"

    出现如下错误: 2016-02-13 22:09:22.318 Test[2757:192106] *** Assertion failure in -[UISearchResultsTableVie ...

  9. java 判断对象是否是某个类的类型方法

    class Do1 { public static void main(String[] args) { AA a=new CC(); if(a instanceof CC) { CC b=(CC)a ...

  10. html的form元素

    <input type="email"><br> <input type="date"><br> <inp ...