PDA

View Full Version : QTableWidget and Decimal places



pshah.mumbai
16th August 2008, 14:28
//Getting the two QTableWidgetItem below
QTableWidgetItem *item1 = this->item(r, 1);
QTableWidgetItem *item2 = this->item(r, 2);

//Copying the value of ietm1 to item2
item2->setText(item1->text());

If the value of item 1 is "100.10" then it is copied as "100.1", how to make it copy as it is - "100.10"

Also is it possible to filter the input to the qtablewidget. I want only decimal input to be accpeted.

Thanks !

spirit
16th August 2008, 14:52
I have the same problem and I wrote the following workaround:


QVariant value = item1->data(Qt::DisplayRole);
// This is trick, because QItemDelegatePrivate::valueToText incorrect convert numbers with floating point
if (value.type() == QVariant::Double)
item2->setData(Qt::DisplayRole, value.toString());

pshah.mumbai
17th August 2008, 05:30
thanks !

a few questions though

Q1. Is the text() same as Data(Qt::DisplayRole) ?

spirit
17th August 2008, 08:30
yup


inline void QTableWidgetItem::setText(const QString &atext)
{ setData(Qt::DisplayRole, atext); }