Ci-dessous, les différences entre deux révisions de la page.
— |
qcheckbox_pyqt4 [2010/09/24 21:20] (Version actuelle) tyrtamos créée |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Case à cocher: QCheckBox ====== | ||
+ | |||
+ | ===== Créer un checkbox ===== | ||
+ | |||
+ | <code python> | ||
+ | checkBox = QtGui.QCheckBox(u" | ||
+ | </ | ||
+ | |||
+ | ===== Initialiser le checkBox ===== | ||
+ | |||
+ | <code python> | ||
+ | checkBox.setChecked(False) | ||
+ | checkBox.setChecked(True) | ||
+ | </ | ||
+ | |||
+ | ===== Tester l' | ||
+ | |||
+ | <code python> | ||
+ | etat = checkBox.isChecked() # donne True si coché et False sinon | ||
+ | </ | ||
+ | |||
+ | ===== Déclencher un évènement à chaque changement d' | ||
+ | |||
+ | <code python> | ||
+ | QtCore.QObject.connect(checkBox, | ||
+ | </ | ||
+ | |||
+ | <code python> | ||
+ | def change(self): | ||
+ | if self.checkBox.isChecked(): | ||
+ | ... | ||
+ | else: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | ===== Petit code test ===== | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | from __future__ import division | ||
+ | |||
+ | import sys | ||
+ | from PyQt4 import QtCore, QtGui | ||
+ | |||
+ | class Fenetre(QtGui.QWidget): | ||
+ | def __init__(self, | ||
+ | super(Fenetre, | ||
+ | self.setWindowTitle(" | ||
+ | |||
+ | # créer le checkBox | ||
+ | self.checkBox = QtGui.QCheckBox(u" | ||
+ | | ||
+ | # initialiser le checkBox à 'non coché' | ||
+ | self.checkBox.setChecked(False) | ||
+ | | ||
+ | # faire que chaque modification du checkBox exécute la méthode ' | ||
+ | QtCore.QObject.connect(self.checkBox, | ||
+ | |||
+ | # création d'une ligne d' | ||
+ | self.lineEdit = QtGui.QLineEdit(self) | ||
+ | |||
+ | # positionnement des widgets dans la fenêtre | ||
+ | posit = QtGui.QGridLayout() | ||
+ | posit.addWidget(self.checkBox, | ||
+ | posit.addWidget(self.lineEdit, | ||
+ | self.setLayout(posit) | ||
+ | |||
+ | def change(self, | ||
+ | """ | ||
+ | if self.checkBox.isChecked(): | ||
+ | self.lineEdit.setText(u" | ||
+ | else: | ||
+ | self.lineEdit.setText(u" | ||
+ | |||
+ | if __name__ == " | ||
+ | app = QtGui.QApplication(sys.argv) | ||
+ | QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(' | ||
+ | fen = Fenetre() | ||
+ | fen.show() | ||
+ | sys.exit(app.exec_()) | ||
+ | </ | ||
+ | |||
+ | |||