Pregunta

Estoy teniendo problemas con mis clases de QTableView y generacodiCodeGode.Para una columna, mi delegado crea una caja de combinación simple y todo funciona bien.Para mi segunda columna, necesito un widget que tiene dos cajas combinadas en un solo widget.

He escrito el siguiente código en mi QItemDelegate, solo para estar claro, este solo muestra el código para mi segunda columna, la que no funciona.La otra caja de combo simple no se muestra ya que funciona bien:

QWidget *UserDefinedUnitsDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const
{
    //set up a simple widget with a layout
    QWidget* pWidget = new QWidget(parent);
    QHBoxLayout* hLayout = new QHBoxLayout(pWidget);
    pWidget->setLayout(hLayout);

    //add two combo boxes to the layout
    QComboBox* comboEditor = new QComboBox(pWidget);    
    QComboBox* comboEditor2 = new QComboBox(pWidget);   

    //now add both editors to this
    hLayout->addWidget(comboEditor);
    hLayout->addWidget(comboEditor2);
    return pWidget;
}

Ahora, esto se muestra bien, pero cuando lo edito y haga clic en otro lugar, no deja de editar.¿Alguien puede ofrecer algún puntero?

Editar: Así que necesito llamar a COMPROMDATA () y CloseDitor () en algún momento.¿Alguien puede ofrecer punteros sobre dónde llamarlos?

gracias.

¿Fue útil?

Solución

Puede mantener el widget del editor como miembro de Class y emitir cometidos cuando el índice actual de uno de los comboboxes ha cambiado.Por lo tanto, puede conectar CorrienteIndexChanged (INT) a una ranura y emitir cometidos desde allí:

QWidget *UserDefinedUnitsDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const
{
    //set up a simple widget with a layout
    pWidget = new QWidget(parent);
    QHBoxLayout* hLayout = new QHBoxLayout(pWidget);
    pWidget->setLayout(hLayout);

    //add two combo boxes to the layout
    QComboBox* comboEditor = new QComboBox(pWidget);    
    QComboBox* comboEditor2 = new QComboBox(pWidget);   

    connect(comboEditor,SIGNAL(currentIndexChanged(int)),this,SLOT(setData(int)));
    connect(comboEditor2,SIGNAL(currentIndexChanged(int)),this,SLOT(setData(int)));

    //now add both editors to this
    hLayout->addWidget(comboEditor);
    hLayout->addWidget(comboEditor2);
    return pWidget;
}

void UserDefinedUnitsDelegate::setData(int val)
{
    emit commitData(pWidget);
}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top