Delegate display on row selection in QTableView



  • Hi,

    I have implemented the custom delegate in QTableView. In One column i have set the ComBox as delegate in QTableView.
    Problem is when i select the row of QTableView then ComboBox is not getting displayed. Combobox is only ge displayed when i clicked on second column where i have set the delegate.
    @ QComboDelegate(QAbstractItemView* view)
    {
    this->view = view;
    }

        virtual QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
        {
            Q_UNUSED(index);
            Q_UNUSED(option);
    
            QComboBox* editor = new QComboBox( parent );
    
            editor->installEventFilter( const_cast<QComboDelegate*>(this) );
            editor->setAutoFillBackground(true);
            QObject::connect( editor, SIGNAL(currentIndexChanged(int)), view, SLOT(sensorModeChanged(int)));
    
            return editor;
        }
    
    
        virtual void setEditorData( QWidget* editor, const QModelIndex& index ) const
        {
            QComboBox* combo = static_cast<QComboBox*>( editor );
    
            combo->addItems( comboList() );
            int idx = QComboDelegate::comboList().indexOf( index.data( Qt::DisplayRole ).toString() );
            combo->setCurrentIndex( idx );
        }
    
        virtual void setModelData( QWidget * editor, QAbstractItemModel* model, const QModelIndex& index ) const
        {
            QComboBox* combo = static_cast<QComboBox*>( editor );
    
            model->setData( index, combo->currentText() );
        }
    
        virtual void updateEditorGeometry(QWidget *editor,
                                          const QStyleOptionViewItem& option, const QModelIndex& index ) const
        {
            Q_UNUSED(index);
            int hCell = option.rect.height();
            int hEditor = editor->sizeHint().height();
            int h = qMax( hCell, hEditor );
            QSize size = option.rect.size();
    
            size.setHeight( h );
            editor->setGeometry( QRect( option.rect.topLeft() - QPoint(0, (h - hCell) / 2), size ) );
        }
    
        /**
         * handle the events anf filter the required events
         */
        virtual bool eventFilter( QObject* obj, QEvent* event )
        {
            if ( event->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Return ) {
                emit commitData( static_cast<QWidget*>(obj) );
                emit closeEditor( static_cast<QWidget*>(obj), EditNextItem );
            }
    
            return false;
        }@
    

    Can you please help me how to do when i select the row then delegate should be displayed ?

    Thanks,
    Neel


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.