I'm trying to create an object (a QGroupBox with 2 QCheckBoxes inside) and replicate it in a 6x4 matrix. I need to access every QGroupBox label and every QCheckBox (and also other widgets i'm willing to put in here later) but i'm stuck in this place:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QCheckBox, QGridLayout, QGroupBox,
QMenu, QPushButton, QRadioButton, QVBoxLayout, QWidget, QButtonGroup)
class RelayCommand(QWidget):
def __init__(self, parent=None):
super(RelayCommand, self).__init__(parent)
self.channelsList = []
grid = QGridLayout()
for column in range(4):
for item in range(6):
#print(type(grid.addWidget(self.createGroup('CH ' + str(item + (column*6))), item, column)))
print('CH ' + str(item + (column*6)) + ' Signal')
relayChannel=('CH ' + str(item + (column*6)) + ' Signal')
self.channelsList.insert(item,RelayChannel(relayChannel))
grid.addWidget(self.channelsList[item], item, column)
self.setLayout(grid)
self.setWindowTitle("PyQt5 Group Box")
self.resize(400, 300)
class RelayChannel(QWidget):
def __init__(self,relayChannel, parent=None):
super(RelayChannel, self).__init__(parent)
def __new__(self,relayChannel):
groupBox = QGroupBox(relayChannel)
self.cb_openLoad = QCheckBox("Open Load")
self.cb_shortCircuit = QCheckBox("Short Circuit")
self.cb_openLoad.clicked.connect(self.openLoadClicked)
vbox = QVBoxLayout()
vbox.addWidget(self.cb_openLoad)
vbox.addWidget(self.cb_shortCircuit)
vbox.addStretch(1)
groupBox.setLayout(vbox) #prev vbox
return groupBox
def openLoadClicked(self):
print(self)
'''if self.cb_openLoad == 2: #openload is checked
print('cb_OpenLoad checked')
self.cb_shortCircuit.setChecked(False)'''
if __name__ == '__main__':
app = QApplication(sys.argv)
clock = RelayCommand()
clock.show()
print(clock.channelsList[0])
sys.exit(app.exec_())
I'm taken it from an example i found on internet, but i can't connect properly the QCheckBoxes signals, since in def openLoadClicked(self):
i see as self
the value of the check box, but inside the function i can't access the other properties like self.cb_shortCircuit
My suspect is that i have to declare all the things i putted in def __new__
in my init
, but in this way i can't return the groupBox element and when i'm creating the matrix nothing happens
Help Please! Thx