Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    1
    2
    2126
    Loading More Posts
    • 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.
    • M
      Macro last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • M
        Macro last edited by

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

        }@

        1 Reply Last reply Reply Quote 0
        • First post
          Last post