⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapdelegate.cpp

📁 Qt4源代码,详细介绍了Qt4编程中的范例
💻 CPP
字号:
#include <QtGui>

#include "mapdelegate.h"


MapDelegate::MapDelegate(QObject *parent)
    : QItemDelegate(parent)
{
}

void MapDelegate::setEditorData(QWidget *editor,
                                    const QModelIndex& index) const
{
	if(index.column() == 0)	// company
	{
        QComboBox *comboEditor = qobject_cast<QComboBox *>(editor);
        if (comboEditor) {
			int i = comboEditor->findText(index.model()->data(index, Qt::EditRole).toString());
			comboEditor->setCurrentIndex(i);
        }		
	}
	else
		return QItemDelegate::setEditorData(editor, index);
}

void MapDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex& index) const
{
	if(index.column() == 0)
	{
		QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
		if(comboBox)
		{
			model->setData(index, comboBox->currentText());
		}
	}
	else
		return QItemDelegate::setModelData(editor, model, index);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -