crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

NetWorm
  опции профиля:
сообщение 9.10.2011, 9:04
Сообщение #1


Студент
*

Группа: Участник
Сообщений: 24
Регистрация: 2.8.2011
Пользователь №: 2784

Спасибо сказали: 0 раз(а)




Репутация:   0  


Есть делегат.....
BoxDelegate::BoxDelegate(QList< QPair<QString,QString> > &aValues, QObject *parent)
    :QItemDelegate(parent){
    Value = aValues;
}

BoxDelegate::~BoxDelegate(){
}

QWidget *BoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const{

    QComboBox *editor = new QComboBox(parent);

    QList< QPair<QString,QString> >::const_iterator it=Value.begin();
    while (it != Value.end())
    {
        const QPair <QString,QString> aPair = *it;
        editor->addItem(aPair.first,aPair.second);
        ++it;
    }
    return editor;
}
void BoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const{
    QComboBox *ComboBox = static_cast<QComboBox*>(editor);
    int value = index.model()->data(index, Qt::DisplayRole).toInt();
    ComboBox->setCurrentIndex(ComboBox->findData(value));
    }

void BoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
    QComboBox *ComboBox = static_cast<QComboBox*>(editor);
    QVariant value = ComboBox->itemData(ComboBox->currentIndex()).toInt();
    model->setData(index, value, Qt::EditRole);
}

void BoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const{
    editor->setGeometry(option.rect);
}


Затем я его присваиваю таблице

BoxDelegate *box = new BoxDelegate(aValues);

ui->sprTable->setItemDelegateForColumn(3,Box);


Все нормально при начале редактирования появляется КомбоБокс... Но когда я выбираю значение из комбобокса, для того чтобы они принялись надо нажимать Enter а как мне сделать чтоб это вызвалось автоматически... Например срабатывал сигнал dataChanged????
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0


RSS Рейтинг@Mail.ru Текстовая версия Сейчас: 21.8.2025, 18:44