# デバッグ用) 自動終了 self.timer = QTimer() self.timer.singleShot(20*1000, self.close)
# :: FileListView self.model = QStringListModel() self.listView = QListView() self.listView.setModel(self.model) self.model.setStringList(["abc", "def", "ghi", "jkl"]) self.listView.clicked.connect(self.flush_listitem)
@Slot() def flush_listitem(self, index): sel1 = index.data(Qt.DisplayRole) sel2 = [i.data(Qt.DisplayRole) for i in self.listView.selectedIndexes()] print sel1 print sel2
https://wiki.qt.io/Style-CSSBased
シグナルの発行元オブジェクトを取得したい場合 https://wiki.qt.io/PySide-Pitfalls-Japanese
(注意) sender()は@Slotを実装してるメソッド内でのみ動く
class Listener(QObject): @Slot() def on_signal(self,*args): print args print self.sender() listner = Listener() btn.someSignal.connect(listener.on_signal)
プロパティのセッターにより,値が変更されると,シグナルを発行できる.
from PySide.QtCore import QObject, Property class MyObject(QObject): def __init__(self, startval=42): QObject.__init__(self) self.ppval = startval def readPP(self): return self.ppval def setPP(self,val): self.ppval = val pp = Property(int, readPP, setPP) obj = MyObject() obj.pp = 47
基本形 http://flame-blaze.net/archives/3094
Threadを使って実用的。ただコード動かない。 http://woodboy644.hatenablog.com/entry/2013/07/30/001910
self.connectでつながないと動かない
# : Quitアクション作成 self.quitAction = QAction("&Quit", self) self.connect(self.quitAction, SIGNAL('triggered()'), qApp, SLOT('quit()')) # self.quitAction.triggered.connect(qApp.quit)