Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it a bug on QTimeEdit?
Forum Updated to NodeBB v4.3 + New Features

Is it a bug on QTimeEdit?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ericma
    wrote on last edited by
    #1

    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);
    }
    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved