Created
July 6, 2015 12:59
-
-
Save fereria/6c8ef59c252d4e6a4545 to your computer and use it in GitHub Desktop.
selectionTest main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -*- coding: utf-8 -*- | |
#*----------------------------------------------*# | |
# 各種モジュール読み込み | |
#*----------------------------------------------*# | |
import os.path | |
import os | |
import sys | |
import re | |
from PySide import QtCore, QtGui | |
import selectionTest as sUI | |
reload(sUI) | |
#*----------------------------------------------*# | |
# MAIN | |
#*----------------------------------------------*# | |
class selUI_Test(QtGui.QDialog): | |
def __init__(self,parent=None): | |
QtGui.QDialog.__init__(self,parent) | |
self.ui = sUI.Ui_Form() | |
self.ui.setupUi(self) | |
self.model = QtGui.QStringListModel() | |
self.ui.listView.setModel(self.model) | |
#とりあえずテストでセット | |
self.model.setStringList(["abc","def","ghi","jkl"]) | |
self.ui.getBtn.clicked.connect(self.getSelection) | |
self.ui.selBtn.clicked.connect(self.setSelection) | |
def getSelection(self): | |
""" | |
リストの選択情報を取得する | |
""" | |
sel = [i.data(QtCore.Qt.DisplayRole) for i in self.ui.listView.selectedIndexes()] | |
mBox = QtGui.QMessageBox() | |
mBox.setText(u"選択しているのは") | |
mBox.setInformativeText("\n".join(sel)) | |
mBox.exec_() | |
def setSelection(self): | |
""" | |
指定した値のリストを選択する | |
""" | |
self.ui.listView.clearSelection() | |
#ボタンをクリックすると、↓が選択できる | |
sel = ["abc","jkl"] | |
sList = self.model.stringList() | |
for i in sel: | |
if i in sList: | |
num = sList.index(i) | |
index = self.model.createIndex(num,0) | |
self.ui.listView.setCurrentIndex(index) | |
#*----------------------------------------------*# | |
# 起動時のコード | |
#*----------------------------------------------*# | |
if __name__ == '__main__': | |
app = QtGui.QApplication(sys.argv) | |
dlg = selUI_Test() | |
dlg.show() | |
sys.exit(app.exec_()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment