Ejemplo n.º 1
0
    def paint(self, painter, option, index):
        # This method will be called every time a particular cell is
        # in view and that view is changed in some way. We ask the 
        # delegates parent (in this case a table view) if the index
        # in question (the table cell) already has a widget associated 
        # with it. If not, create one with the text for this index and
        # connect its clicked signal to a slot in the parent view so 
        # we are notified when its used and can do something. 
        if not self.parent().indexWidget(index):
            rowData = Settings.getLogLevelsModel().getRowData(index)

            col = QColor(rowData[2])
            self.frm = ColorPickerFrame()
            # Set index of current table row
            self.frm.setIndex(index)
            self.frm.setStyleSheet("QWidget { background-color: %s }" % col.name())
            self.frm.setGeometry(130, 22, 100, 100)
            self.frm.setLineWidth(0)
            self.frm.setMidLineWidth(2)
            self.frm.setFrameStyle(QFrame.Box)
            self.frm.setFrameShadow(QFrame.Sunken)
            self.connect(self.frm, QtCore.SIGNAL('colorPickerClicked'), self.colorPickerClicked)
            self.parent().setIndexWidget(index, self.frm)
Ejemplo n.º 2
0
    def colorPickerClicked(self, item):
        col = QtGui.QColorDialog.getColor()

        if col.isValid():
            item.setStyleSheet("QWidget { background-color: %s }" % col.name())
            Settings.getLogLevelsModel().setData(item.getIndex(), col.name(), QtCore.Qt.DisplayRole)