QComboBox focus is not shown with Gray dotted line border when Enter/Return key is pressed



  • Hi...

    I have a QLineEdit and a QComboBox, when the Focus is in the QLineEdit and if i press Enter/Return key the focus has to be changed to the QComboBox. I tried using event filters and the focus is changing to the QComboBox, but the problem is when the focus is in the QComboBox, it is not showing with the Dotted lines border.... Again if i press Enter the focus has to be changed to the QLineEdit. This one is also not working. Please post your suggestions..
    @
    if(keyEvent->key() == Qt::Key_Enter || keyEvent->key()== Qt::Key_Return)
    {
    this->focusNextChild();
    }
    @

    Note: It works Fine if i press the Tab key for changing the Focus.



  • Hi...

    This code works Fine for changing the focus from the Last Component(QComboBox) to the First Component (QLineEdit). But Still that Dotted Lines Border for the QComboBox (when it has the Focus) is not Working.. Please post your suggestions....

    @bool ComboFocus::eventFilter(QObject *obj, QEvent *event)
    {
    if(event->type() == QEvent::KeyPress)
    {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    if(keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
    {
    if(children().indexOf(obj) == children().count()-1)
    {
    QWidget firstwidget = qobject_cast<QWidget>(children().at(0));
    if(firstwidget != NULL)
    {
    firstwidget->setFocus();
    }
    else
    {
    this->focusNextChild();
    }
    }
    else
    {
    this->focusNextChild();
    }

            return QWidget::eventFilter(obj, event);
        }
    }
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.