Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delegate display on row selection in QTableView

Delegate display on row selection in QTableView

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neel2818
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved