示例#1
0
            model.setData(model.index(index.row(), 0), ImitParams.get_state_icon(state_code), Qt.DecorationRole)
            model.blockSignals(False)
        if index.column() == 2:            
            err_code = self._source_model.get_error_code(model.data(model.index(index.row(), 0)).toString(), editor.currentText())
            self._source_model.setData(self._source_model.index(index.row(), DEV_ERR_CODE_INDEX), err_code)
            index.model().setData(index, editor.currentText())

    def sizeHint(self, option, index):
        return QSize(option.decorationSize.width(), 25)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    unit_model = UnitModel(None)
    unit_model.init_dev()
    unit_delegate = UnitDelegate(unit_model)
    unit_view = PropertyExplorer()
    unit_view.setItemDelegate(unit_delegate)
    unit_view.set_source_model(unit_model)
    unit_view.resize(240, 480)
    unit_view.show()
    view = QTreeView()
    view.setModel(unit_model)
    view.show()    
    sys.exit(app.exec_())






示例#2
0
        if index.column() == 1:
            param_name = index.model().data(index.model().index(index.row(), 0)).toString()
            value_type = self._source_model.data(self._source_model.index(index.row(), PARAM_TYPE_INDEX)).toString()
            if value_type == u'enum':
                value_name = editor.currentText()
                value_code = self._source_model.get_value_code(param_name, value_name)
                self._source_model.setData(self._source_model.index(index.row(), VALUE_CODE_INDEX), value_code)
                model.setData(index, value_name)
            if value_type == u'numeric':
                value = editor.value()
                model.setData(index, value)
                self._source_model.setData(self._source_model.index(index.row(), VALUE_CODE_INDEX), QString.number(value))

    def sizeHint(self, option, index):
        return QSize(option.decorationSize.width(), 25)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    param_model = ParamModel()
    param_delegate = ParamDelegate(param_model)
    param_view = PropertyExplorer()
    param_view.setItemDelegate(param_delegate)
    param_view.set_source_model(param_model)
    param_view.resize(240, 480)
    param_view.show()
    view = QTreeView()
    view.setModel(param_model)
    view.show()    
    sys.exit(app.exec_())