Important: Please read the Qt Code of Conduct -

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!
    QItemEditorFactory *factory = new QItemEditorFactory;
    QItemEditorCreatorBase *timeCreator =
    new QStandardItemEditorCreator<QTimeEdit>();
    factory->registerEditor(QVariant::Time, timeCreator);



    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->resize(150, 50);
    for (int i = 0; i < 3; ++i) {
        QPair<QString, QTime> pair =;
        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);
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(table, 0, 0);
    setWindowTitle(tr("Time Editor Factory"));


    the QDateTimeEdit::setTime is
    @void QDateTimeEdit::setTime(const QTime &time)
    if (time.isValid()) {
    d->setValue(QDateTime(d->value.toDate(), time, d->spec), EmitIfChanged);

Log in to reply