Skip to content

Instantly share code, notes, and snippets.

@FGtatsuro
Created June 30, 2013 16:35
Show Gist options
  • Save FGtatsuro/5895864 to your computer and use it in GitHub Desktop.
Save FGtatsuro/5895864 to your computer and use it in GitHub Desktop.
PySideのスロットを定義する際の注意(2) ref: http://qiita.com/FGtatsuro/items/524c85c5df88bdcc0135
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PySide.QtGui import QApplication, QMainWindow, QWidget, QPushButton,\
QVBoxLayout
class OnOffButtonWidget(QWidget):
def __init__(self):
super(OnOffButtonWidget, self).__init__()
self.__init_ui()
self.__init_event()
def __init_ui(self):
self.button1 = QPushButton('button1', self)
self.button2 = QPushButton('button2', self)
self.button1.setCheckable(True)
self.button2.setCheckable(True)
vbox = QVBoxLayout()
vbox.addWidget(self.button1)
vbox.addWidget(self.button2)
self.setLayout(vbox)
def __init_event(self):
self.button1.clicked.connect(self.without_arg)
self.button2.clicked[bool].connect(self.with_arg)
def without_arg(self):
print 'without_arg'
def with_arg(self, clicked):
print 'with arg:{0}'.format(clicked)
def main():
app = QApplication(sys.argv)
window = QMainWindow()
window.setCentralWidget(OnOffButtonWidget())
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
without_arg (button1クリック時の出力)
with arg:True (button2クリック時の出力)
self.button2.clicked[bool].connect(self.with_arg)
# (object).(signal).connect(slot)
self.button1.clicked.connect(self.without_arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment