문제

QTableViewQItemDelegate 클래스에 문제가 있습니다.한 열의 경우 내 대리자가 간단한 콤보 상자를 만들고 모든 것이 잘 작동합니다.내 두 번째 열의 경우 단일 위젯에 두 개의 콤보 상자가있는 위젯이 필요합니다.

다음 코드를 내 QItemDelegate에 썼습니다.이를 지우기 위해서만 두 번째 열에 대한 코드 만 표시하지 않고 작동하지 않는 코드입니다.다른 간단한 콤보 상자가 잘 작동하지 않으므로

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;
}
.

이제는 이로 인해 괜찮아요.하지만 편집 할 때 다른 위치를 클릭하면 편집을 멈추지 않습니다.누구든지 포인터를 제공 할 수 있습니까?

편집 : 일부 시점에서 commitData ()와 CloseEditor ()를 호출해야합니다.누구든지 이들을 어디에서 부를 수 있는지에 대한 포인터를 제공 할 수 있습니까?

감사합니다.

도움이 되었습니까?

해결책

콤보 로스 중 하나의 현재 색인이 변경되었을 때 편집기 위젯을 클래스의 구성원으로 유지하고 commitData를 방출 할 수 있습니다.따라서 CurrentIndExchanged (int)를 슬롯에 연결하고 commitData를 emit commitData를

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);
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top