1

builing on teh following example, how can i pass/access more properties then the 'state' of the QCheckBox? In this case I am looking to build a more dynamic function that can be used for multiple buttons and saves all status in a dict.

something like this (I am mainly looking for the correct name of 'objectName' as it is used with 'state' in the 'ILCheckbox_changed' definition, and maybe more generally how I can find whcih other properties I can pass)

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class SelectionWindow(QMainWindow):
    def __init__(self, parent=None):
        super(SelectionWindow, self).__init__()

        self.ILCheck = False
        ILCheckbox = QCheckBox(self)
        ILCheckbox.setCheckState(Qt.Unchecked)

        self.check_box_dict = {}
        ILCheckbox.stateChanged.connect(self.ILCheckbox_changed)

        MainLayout = QGridLayout()
        MainLayout.addWidget(ILCheckbox, 0, 0, 1, 1)

        self.setLayout(MainLayout)

    def ILCheckbox_changed(self, state, objectName):
        self.ILCheck = (state == Qt.Checked)

        print(self.ILCheck)
        self.check_box_dict[objectName] = self.ILCheck

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = SelectionWindow()

    window.show()
    sys.exit(app.exec_())
Community
  • 1
  • 1
Tobias
  • 59
  • 5
  • I actually just discovered that just the state is passed, alternatively, I would be looking for some way to e.g. pass over the specific CheckBox with all of its properties, someting like { ILCheckbox.stateChanged.connect(self.ILCheckbox_changed(ILCheckbox)) [...] def ILCheckbox_changed(self, check_box): print(check_box.objectName()) } – Tobias Feb 14 '17 at 15:18

1 Answers1

0

In every slot you can access the object that sends the signal with the function self.sender()

def ILCheckbox_changed(self, state):
    self.ILCheck = (state == Qt.Checked)
    print(self.ILCheck)
    self.check_box_dict[self.sender()] = self.ILCheck
    print(self.check_box_dict)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241