[Qt-interest] QTableWidgetItem with Validator (only numbers) and Range
Matthias Pospiech
matthias.pospiech at gmx.de
Sat May 2 20:25:34 CEST 2009
I want to have cells in a QTableWidget that accept only numbers in a
specified range. Think of a QDoubleSpinBox without the buttons.
I could not see from the docs that such functionality is built into the
QTableWidgetItem. So I tried to add a QDoubleSpinBox instead of a QString
for the constructor, but that fails.
QDoubleSpinBox * spinbox = new QDoubleSpinBox(this);
spinbox->setRange(0,20000);
spinbox->setDecimals(2);
spinbox->setValue(power);
newItem = new QTableWidgetItem(spinbox);
instead of
newItem = new QTableWidgetItem(QString("%1").arg(power));
So, how do I add the functionality of the QDoubleSpinBox into the
QTableWidgetItem. The docs say something about subclassing, but I have
no idea how that should possibly look like. Exept that I could reinvent
the wheel and copy most of QDoubleSpinBox code into a subclassed
class of QTableWidgetItem...
Seems to me like a standard problem. Maybe someone has a solution for me?
Matthias
More information about the Qt-interest-old
mailing list