Beispiel #1
0
    def createEditor(self, parent, option, index):
        button = QPushButton(self.icon, u'', parent)
        button.setCheckable(True)
        button.setAutoFillBackground(True)
        button.setFocusPolicy(Qt.NoFocus)

        #local function, has knowledge of button (a delegate is stateless).
        def setstyle(checked):
            if checked:
                style = self.style_on
                text = self.text_on
            else:
                style = self.style_off
                text = self.text_off
            button.setStyleSheet(style)
            button.setText(text)

        def emit():
            self.setModelData(button, index.model(), index)

        button.setstyle = setstyle
        self.connect(button, SIGNAL('clicked(bool)'), button.setstyle)
        self.connect(button, SIGNAL('clicked(bool)'), self.setClicked)
        self.connect(button, SIGNAL('toggled(bool)'), emit)

        return button