Is it a bug on QTimeEdit?
-
Help document mentioned that QTimeEdit is the standard editor to QTime.
I make the following code. It can work first time. but the data is changed to QDatetime type, so it can't work when I doublicked it second time. I debug it and found that QTimeEdit inherit from QDateTimeEdit, QTimeEdit didn't implement function setTime, same time QDateTimeEdit implement the function, but the function changed the QTime type to QDateTime type.QDateEdit has the same problem. I think it's a bug, please help to confirm that. Any help will be appreciated!
@Window::Window()
{
QItemEditorFactory *factory = new QItemEditorFactory;
QItemEditorCreatorBase *timeCreator =
new QStandardItemEditorCreator<QTimeEdit>();
factory->registerEditor(QVariant::Time, timeCreator);QItemEditorFactory::setDefaultFactory(factory); createGUI();
}
void Window::createGUI()
{
QList<QPair<QString, QTime> > list;
list << QPair<QString, QTime>(tr("Alice"), QTime(10, 10, 10)) <<
QPair<QString, QTime>(tr("Neptun"), QTime(1, 2, 3)) <<
QPair<QString, QTime>(tr("Ferdinand"), QTime(5, 5, 4));QTableWidget *table = new QTableWidget(3, 2); table->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("time")); table->verticalHeader()->setVisible(false); table->resize(150, 50); for (int i = 0; i < 3; ++i) { QPair<QString, QTime> pair = list.at(i); QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first); QTableWidgetItem *colorItem = new QTableWidgetItem; colorItem->setData(Qt::DisplayRole, pair.second); table->setItem(i, 0, nameItem); table->setItem(i, 1, colorItem); } table->resizeColumnToContents(0); table->horizontalHeader()->setStretchLastSection(true); QGridLayout *layout = new QGridLayout; layout->addWidget(table, 0, 0); setLayout(layout); setWindowTitle(tr("Time Editor Factory"));
}@
the QDateTimeEdit::setTime is
@void QDateTimeEdit::setTime(const QTime &time)
{
Q_D(QDateTimeEdit);
if (time.isValid()) {
d->clearCache();
d->setValue(QDateTime(d->value.toDate(), time, d->spec), EmitIfChanged);
}
}@