crossplatform.ru

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

> Проблемы с делегатом, Делегат времени
Patricul
  опции профиля:
сообщение 12.8.2011, 13:07
Сообщение #1


Новичок


Группа: Новичок
Сообщений: 9
Регистрация: 1.8.2011
Пользователь №: 2779

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




Репутация:   0  


Столкнулся со следующей проблемой!
Пытаюсь внедрить делегат на изменение времени в свой проект:
В конструкторе подключаю:
  
m_pTrackRecordView->setItemDelegate(new MyDEDelegate(working_enteringdate, this)); // номер столбца и виджет
m_pTrackRecordView->setItemDelegate(new MyDEDelegate(working_sakingdate, this));

Но при клике на соответствующий индекс (в моём случае Дата увольнения) у меня происходит следующая картина:
Почему-то редактирование смещается в индекс с значениями 0 (row) и 0 (column). И мне непонятно почему так происходит...


Код делегата:
  
class MyDEDelegate : public QItemDelegate
{
        Q_OBJECT
   public:
        MyDEDelegate(int durationColumn,
                    QObject *parent = 0);
      QWidget *createEditor( QWidget *parent,  const QStyleOptionViewItem &option,
                                  const QModelIndex &index) const;
       void setEditorData(QWidget *editor,  const QModelIndex &index) const;

       void setModelData(QWidget *editor, QAbstractItemModel *model,
                                    const QModelIndex &index) const;
       void updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option,
                                    const QModelIndex &index) const;

    private:
       bool m_calpopup;
       int durationColumn;
  };


  
MyDEDelegate::MyDEDelegate( int durationColumn, QObject *parent)  : QItemDelegate(parent)


       {
      this->durationColumn = durationColumn;

       }

      QWidget *MyDEDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option,
                                                            const QModelIndex &index ) const
      {
      if (index.column() == durationColumn)
      {
       QDateEdit *editor = new QDateEdit(parent);
       editor->setCalendarPopup(m_calpopup);
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
       return editor;
      }
      else
       return QItemDelegate::createEditor(parent, option, index);
       }

     void MyDEDelegate::setEditorData( QWidget *editor, const QModelIndex &index) const
    {
      if(index.column() == durationColumn)
     {
     QDate value = index.model()->data(
               index, Qt::EditRole).toDate();
      QDateEdit *de = static_cast<QDateEdit*>(editor);
       de->setDate(value);
     }
      else
          QItemDelegate::setEditorData(editor, index);
     }

    void MyDEDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,  
                                        const QModelIndex& index) const

        {
       if(index.column() == durationColumn)
        {
           QDateEdit *de = static_cast<QDateEdit*>(QDate::currentDate(),editor);
      de->interpretText();
      QDate value  = de->date();
       model->setData(index, value);
     }
       else
         QItemDelegate::setModelData(editor, model, index);

    }

   void MyDEDelegate::updateEditorGeometry(
               QWidget *editor,
             const QStyleOptionViewItem &option,
              const QModelIndex& /* index */) const {
}


И ещё меня интересует вопрос! Можно ли подкдючать один и тот же делегат сразу к двум индексам? Не то он у меня работает только при изменении индекса working_sakingdate.
Заранее спасибо...
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

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


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


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




RSS Текстовая версия Сейчас: 19.4.2024, 23:16