#!/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. [Linux 小技巧] Ubuntu 14.04 下编译、安装、配置最新开发版 GoldenDict

    1. 背景介绍 GoldenDict 是一款非常优秀的跨平台电子词典软件,支持 StarDict.Babylon 等多种词典.其 PC 版基于 Qt 编写,完全免费.开源且没有广告.GoldenDic ...

  2. Sybase常用函数

    ==================================常用函数===========================================字符串函数1)ISNULL(EXP1, ...

  3. SQL自连接(源于推荐算法中的反查表问题)

    ”基于用户的协同过滤算法“是推荐算法的一种,这类算法强调的是:把和你有相似爱好的其他的用户的物品推荐给你. 要实现该推荐算法,就需要计算和你有交集的用户,这就要用到物品到用户的反查表. 先举个例子说明 ...

  4. $http post传值的问题

    var app = angular.module("myApp", [], function ($httpProvider) { $httpProvider.defaults.he ...

  5. Linux 编译安装httpsqs

    wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz tar zxvf libevent-2.0.12-stab ...

  6. 深入了解session

    session在web开发中是一个非常重要的概念,这个概念很抽象,很难定义,也是最让人迷惑的一个名词,也是最多被滥用的名字之一,在不同的场合,session一次的含义也很不相同.这里只探讨HTTP S ...

  7. git基础使用小记

    一.安装步骤省略二.运行“Git Bash“在打开的窗口中输入:ssh-keygen -t rsa -C "my@gmail.com" 会提示SSH Public Keys存放的位 ...

  8. ubuntu 启用apache2 虚拟机配置

    Ubuntu 启用apache2 虚拟机配置 http://jingyan.baidu.com/article/5d6edee20b78e999eadeecf7.html

  9. Python入门-----Windows安装

    摘要:Python,windows安装 1.进入python的官方网站下载:https://www.python.org 点击Download,选择windows版本:

  10. About abstract class.

    Abstract means should be realized. Virtual means could be overrided. It is very different!