0

i have Qtablewidget i have implemented a delegate for that table

like so : Num(default) | item(Qcombobox) | -qty-(QdoubleSpinBox)| Price(QdoubleSpinBox)|subtotal (QdoubleSpinBox)

i want to calculate subtotal( qty * price ) for each row using delegate, but really i don't know how to emit data from delegate

i tried this from my custom delegate

QWidget *customTableSellDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(!index.isValid())
        return QStyledItemDelegate::createEditor(parent,option,index);

    int col= index.column();

    if(col == 1)
    {
        QComboBox *comboboxEditor = new QComboBox(parent);
        return comboboxEditor;
    }
    // col3
    else if(col ==2 || col ==3 || col ==4 || col == 5 || col == 6 || col == 7)
    {
        QDoubleSpinBox *doubleSpinBoxEditor = new QDoubleSpinBox(parent);
        doubleSpinBoxEditor->setInputMethodHints(Qt::ImhFormattedNumbersOnly);
        doubleSpinBoxEditor->setRange(0.000000,999999999);
        doubleSpinBoxEditor->setSuffix(" D.A");
        doubleSpinBoxEditor->setDecimals(2);
        doubleSpinBoxEditor->setFrame(false);

        if(col == 2 || col == 3)
        {
            connect(doubleSpinBoxEditor,SIGNAL(valueChanged(double)),this,SLOT(testSlot(double)));
        }

        return doubleSpinBoxEditor;
    }else{
        return QStyledItemDelegate::createEditor(parent,option,index);
    }

}

so , what's the best way to do this ?

1 Answer 1

0

after thinking i get the solution her is the code

Note: this is depand in my logic , you can change it as you want

   QTableWidgetItem *item= NULL;
    for(int row=0; row < ui->tableWidget->rowCount(); row++)
    {
        for (int col=0; col< ui->tableWidget->columnCount(); col++)
        {

            item = new QTableWidgetItem;
            ui->tableWidget->setItem(row,col,item);


        }
    }
    for(int row =0; row < ui->tableWidget->rowCount(); row++)
    {
        for(int col=0; col < ui->tableWidget->columnCount(); col++)
        {
            if(row != 0)
                ui->tableWidget->item(row,col)->setFlags(Qt::NoItemFlags);
            else{
                if(col == 0 || col == 4 || col == 5 || col == 7 || col == 6)
                    ui->tableWidget->item(row,col)->setFlags(Qt::NoItemFlags);

                      }

        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.