0

I want to change for example 2.16 into 2,16 in a table. This is my code

{
    .......
    connect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(change_string(QTableWidgetItem*)));
}

void MyClass::change_string(QTableWidgetItem* input_item)
{
    if (input_item->text() != "") {
        if (input_item->text().contains(".", Qt::CaseSensitive)) {
            input_item->text().replace(".", ",", Qt::CaseSensitive);
        }
    }
}

My code run normally, I have debugged, the line input_item->text().replace(".", ",", Qt::CaseSensitive); is implemented. But after that, the table still shows 2.16, not 2,16. I don't know why? Do I need to refresh table or something like that after replacing the string?

frogatto
  • 28,539
  • 11
  • 83
  • 129
trangan
  • 341
  • 8
  • 22

1 Answers1

1

You don't setText in your code. Try this:

QString text = input_item->text().replace(".", ",", Qt::CaseSensitive);
input_item->setText(text);
frogatto
  • 28,539
  • 11
  • 83
  • 129