Skip to content

Instantly share code, notes, and snippets.

@fereria
Created February 7, 2015 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/9e0683739377739e1340 to your computer and use it in GitHub Desktop.
Save fereria/9e0683739377739e1340 to your computer and use it in GitHub Desktop.
ProxyModel Test
## -*- coding: utf-8 -*-
import os.path
import sys
from PySide import QtCore, QtGui
from PySide.QtUiTools import QUiLoader
pathThisFile = os.path.dirname(os.path.abspath(__file__))
class proxyModelTest(QtGui.QDialog):
uiFile = pathThisFile + "/proxyModel.ui"
def __init__(self,parent=None):
super(proxyModelTest,self).__init__(parent)
self.setWidget()
layout = QtGui.QVBoxLayout()
layout.addWidget(self.ui)
self.setLayout(layout)
#ModelSet
#抽出前のリスト
self.sourceModel = QtGui.QStandardItemModel()
self.ui.sourceView.setModel(self.sourceModel)
self.setItem()
#抽出後のリスト
self.proxyModel = QtGui.QSortFilterProxyModel()
self.proxyModel.setDynamicSortFilter(True)
self.ui.proxyView.setModel(self.proxyModel)
self.proxyModel.setSourceModel(self.sourceModel)
self.ui.lineEdit.textChanged.connect(self.changeFilter)
def setItem(self):
itemList = ["aaabbbccc","dddeeefff","ggghhhiii","abc","def"]
for i in itemList:
item = QtGui.QStandardItem(i)
self.sourceModel.appendRow(item)
def setWidget(self):
qLoader = QUiLoader()
qFile = QtCore.QFile(self.uiFile)
qFile.open(QtCore.QFile.ReadOnly)
self.ui = qLoader.load(qFile,self)
qFile.close()
def changeFilter(self):
#QtCore.Qt.CaseInsensitive 大文字小文字を区別しない
regExp = QtCore.QRegExp(self.ui.lineEdit.text(),
QtCore.Qt.CaseInsensitive,
QtCore.QRegExp.RegExp)
self.proxyModel.setFilterRegExp(regExp)
app = QtGui.QApplication(sys.argv)
a = proxyModelTest()
a.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment