Skip to content

Instantly share code, notes, and snippets.

@fereria
Created August 17, 2020 08:35
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/20a6aba7dce044424dbf624ef27a3801 to your computer and use it in GitHub Desktop.
Save fereria/20a6aba7dce044424dbf624ef27a3801 to your computer and use it in GitHub Desktop.
## -*- coding: utf-8 -*-
#model/viewの基本
import sys
from PySide2 import QtCore, QtWidgets
class testView(QtWidgets.QDialog):
def __init__(self, parent=None):
super(testView, self).__init__(parent)
layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)
self.view = QtWidgets.QListView()
self.edit = QtWidgets.QLineEdit()
layout.addWidget(self.view)
layout.addWidget(self.edit)
#中のデータ(モデル)を作成して、Viewにセット
self.model = QtCore.QStringListModel(["test", "a", "b", "c", "hello world"])
self.proxy = QtCore.QSortFilterProxyModel()
self.proxy.setSourceModel(self.model)
self.view.setModel(self.proxy)
self.edit.textChanged.connect(self.setRegexp)
def setRegexp(self):
regExp = QtCore.QRegExp(
self.edit.text(),
QtCore.Qt.CaseSensitive,
QtCore.QRegExp.Wildcard
)
self.proxy.setFilterRegExp(regExp)
self.proxy.layoutChanged.emit()
#アプリケーション実行
app = QtWidgets.QApplication(sys.argv)
test = testView()
test.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment