M
M
Mercury132019-06-07 17:29:49
Qt
Mercury13, 2019-06-07 17:29:49

How to catch the moment when an editor is created in QComboBox?

We write a component based on QComboBox. We are trying to make it at least a little universal - and for this you need to register the installation of events. Including the lineEdit()->textEdited event. Initially this lineEdit is not present, it appears when the combobox becomes editable. What is the best way to solve this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2019-06-07
@Mercury13

Again, you have to answer on your own.

void TimedWideComboBox::connectToEditor()
{
    if (!lineEdit())
        return;
    connect(lineEdit(), &QLineEdit::textEdited, this, &This::origDataChanged);
}

bool TimedWideComboBox::event(QEvent* ev)
{
    bool b = Super::event(ev);
    switch (ev->type()) {
    case QEvent::ChildAdded: {
            auto ev1 = static_cast<QChildEvent*>(ev);
            if (ev1->child() == lineEdit()) {
                connectToEditor();
                return true;
            }
        } break;
    default:;
    }
    return b;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question