質問

私のQTableViewおよびQItemDelegateクラスに問題があります。1列のために私の代理人は単純なコンボボックスを作成し、すべてがうまく機能します。私の2番目の列には、1つのウィジェットに2つのコンボボックスがあるウィジェットが必要です。

私は私のQItemDelegateに次のコードを書いています。これは私の2番目の列のコードのみを表示するだけです。他のシンプルなコンボボックスはうまく機能しないので表示されていません:

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()をいくつかの時点で呼び出す必要があります。誰もがこれらの呼び出し先のポインタを提供することができますか?

ありがとう。

役に立ちましたか?

解決

ComboBoxesの1つの現在のインデックスが変更されたときに、エディタウィジェットをクラスのメンバーとして保つことができます。そのため、CurrentIndexChanged(int)をスロットに接続し、そこから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