4 pièce(s) jointe(s)
Récupérer l'état d'un checkbox QML avec PyQt5
Bonjour à tous,
Je sollicite votre aide car je ne sais pas comment faire pour récupérer l'état de mes checkbox avec PyQt5 (je suis électronicien et je programme plus sur micro que sur PC, alors allez-y doucement :lol:)
Voici ce que j'ai fait en QML :
Lorsque j'appuie sur VALIDER j'aimerai connaitre l'état de mes CheckBox.
Pièce jointe 438218 Pièce jointe 438225
Avec le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| import QtQuick 2.9
import QtQuick.Controls 2.2
Page {
width: 1800
height: 1200
objectName: "choix_CTX300"
property alias busyIndicator: busyIndicator
property alias textField1: textField1
property alias textField: textField
property alias button2: button2
property alias button1: button1
property alias page: page
property alias checkBox1: checkBox1
property alias checkBox: checkBox
property alias button: button
header: Label {
id: label
height: 70
color: "#ff00ff"
text: qsTr("CTX300")
font.bold: true
verticalAlignment: Text.AlignVCenter
font.pixelSize: Qt.application.font.pixelSize * 2
padding: 10
Rectangle {
id: rectangle
height: 70
color: "#ff00ff"
anchors.left: parent.left
anchors.leftMargin: 105
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
BusyIndicator {
id: busyIndicator
x: 1621
running: false
anchors.right: parent.right
anchors.rightMargin: 8
anchors.top: parent.top
anchors.topMargin: 8
}
}
}
Rectangle {
id: rectangle1
color: "#000000"
anchors.fill: parent
Rectangle {
id: rectangle2
x: 436
width: 164
color: "#ffffff"
anchors.bottom: parent.bottom
anchors.bottomMargin: 754
anchors.top: parent.top
anchors.topMargin: 0
anchors.right: parent.right
anchors.rightMargin: 0
Button {
id: button
objectName: "choix_produit"
x: 9
y: 192
width: 147
height: 53
text: qsTr("VALIDER")
font.pointSize: 20
font.bold: true
anchors.right: parent.right
anchors.rightMargin: 8
}
CheckBox {
id: checkBox
objectName: "norme_CE"
x: 9
y: 8
width: 147
height: 66
text: qsTr("CE")
font.bold: true
font.pointSize: 22
}
CheckBox {
id: checkBox1
objectName: "norme_CSA"
x: 9
y: 93
width: 147
height: 71
text: qsTr("CSA")
property bool property0: true
font.bold: true
font.pointSize: 22
}
} |
Voici mon bout de code Python
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtProperty
from PyQt5.QtWidgets import QApplication, QCheckBox
from PyQt5.QtQuick import QQuickView
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load('main.qml')
win = engine.rootObjects()[0]
norme_CE = win.findChild(QObject, "norme_CE")
norme_CSA = win.findChild(QObject, "norme_CSA")
choix_produit = win.findChild(QObject, "choix_produit")
def commande_sefelec():
print("lancer")
print (norme_CE.isChecked())
choix_produit.clicked.connect(commande_sefelec)
win.show()
sys.exit(app.exec_()) |
Pour commencer mes essais j'ai juste fait un print("lancer") et un print (norme_CE.isChecked()) qui, je pensais, allait me renvoyer un bool mais je pensais mal :calim2:
J'ai une belle erreur du type
Pièce jointe 438235
Voilà ! Merci de votre aide.
Patrick