Event QComboBox to Custom QLineEdit










0
















The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.



I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().



QCustomCombo::QCustomCombo():
m_lineEdit(new QCustomLineEdit)

setEditable(true);
setLineEdit(m_lineEdit);


bool QCustomCombo::event(QEvent * event)

if(event->type() == QEvent::KeyPress)

QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)

//pass to lineEdit();
//I have tried 'return true/false and QWidget::event(event)'
//I have also tried commenting out QCustomCombo::event, same problem


return QWidget::event(event);



QCustomLineEdit



bool QCustomLineEdit::event(QEvent * event)

if(event->type() == QEvent::KeyPress)

QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_tab)

//Do custom Stuff
return true;

if(keyEvent->key() == Qt::Key_Right)

//Do custom Stuff
return true;


return QWidget::event(event);



The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.










share|improve this question




























    0
















    The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.



    I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().



    QCustomCombo::QCustomCombo():
    m_lineEdit(new QCustomLineEdit)

    setEditable(true);
    setLineEdit(m_lineEdit);


    bool QCustomCombo::event(QEvent * event)

    if(event->type() == QEvent::KeyPress)

    QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
    if(keyEvent->key() == Qt::Key_tab)

    //pass to lineEdit();
    //I have tried 'return true/false and QWidget::event(event)'
    //I have also tried commenting out QCustomCombo::event, same problem


    return QWidget::event(event);



    QCustomLineEdit



    bool QCustomLineEdit::event(QEvent * event)

    if(event->type() == QEvent::KeyPress)

    QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
    if(keyEvent->key() == Qt::Key_tab)

    //Do custom Stuff
    return true;

    if(keyEvent->key() == Qt::Key_Right)

    //Do custom Stuff
    return true;


    return QWidget::event(event);



    The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.










    share|improve this question


























      0












      0








      0









      The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.



      I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().



      QCustomCombo::QCustomCombo():
      m_lineEdit(new QCustomLineEdit)

      setEditable(true);
      setLineEdit(m_lineEdit);


      bool QCustomCombo::event(QEvent * event)

      if(event->type() == QEvent::KeyPress)

      QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
      if(keyEvent->key() == Qt::Key_tab)

      //pass to lineEdit();
      //I have tried 'return true/false and QWidget::event(event)'
      //I have also tried commenting out QCustomCombo::event, same problem


      return QWidget::event(event);



      QCustomLineEdit



      bool QCustomLineEdit::event(QEvent * event)

      if(event->type() == QEvent::KeyPress)

      QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
      if(keyEvent->key() == Qt::Key_tab)

      //Do custom Stuff
      return true;

      if(keyEvent->key() == Qt::Key_Right)

      //Do custom Stuff
      return true;


      return QWidget::event(event);



      The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.










      share|improve this question

















      The Problem: I have a custom event on QLineEdit inside a custom QComboBox and only specific events are being passed from QComboBox to QLineEdit when I want. I can't get tab to be passed.



      I want when an event passed to QComboBox it will be passed to the QComboBox->lineEdit().



      QCustomCombo::QCustomCombo():
      m_lineEdit(new QCustomLineEdit)

      setEditable(true);
      setLineEdit(m_lineEdit);


      bool QCustomCombo::event(QEvent * event)

      if(event->type() == QEvent::KeyPress)

      QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
      if(keyEvent->key() == Qt::Key_tab)

      //pass to lineEdit();
      //I have tried 'return true/false and QWidget::event(event)'
      //I have also tried commenting out QCustomCombo::event, same problem


      return QWidget::event(event);



      QCustomLineEdit



      bool QCustomLineEdit::event(QEvent * event)

      if(event->type() == QEvent::KeyPress)

      QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
      if(keyEvent->key() == Qt::Key_tab)

      //Do custom Stuff
      return true;

      if(keyEvent->key() == Qt::Key_Right)

      //Do custom Stuff
      return true;


      return QWidget::event(event);



      The QLineEdit has a custom event for left and right arrow and tab. Only the arrows get passed. But I can't get the tab to pass to it.







      c++ qt qt5 qcombobox qlineedit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 17:06









      eyllanesc

      79.2k103257




      79.2k103257










      asked Nov 14 '18 at 16:47









      DevilGaleDevilGale

      114




      114






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Use QApplication::notify



          bool QCustomCombo::event(QEvent * event)

          if(event->type() == QEvent::KeyPress)

          QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
          if(keyEvent->key() == Qt::Key_Tab)

          qApp->notify(m_lineEdit, event);
          return true;


          return QWidget::event(event);






          share|improve this answer























          • How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

            – DevilGale
            Nov 14 '18 at 21:41











          • @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

            – eyllanesc
            Nov 15 '18 at 2:07



















          1















          I want when an event passed to QComboBox it will be passed to the
          QComboBox->lineEdit().




          installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *) method gets called, object A's eventFilter(QObject *, QEvent *) method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).



          You can use that so that your CustomCombo can see and react to events that would otherwise go directly to the `QComboBox.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305074%2fevent-qcombobox-to-custom-qlineedit%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Use QApplication::notify



            bool QCustomCombo::event(QEvent * event)

            if(event->type() == QEvent::KeyPress)

            QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
            if(keyEvent->key() == Qt::Key_Tab)

            qApp->notify(m_lineEdit, event);
            return true;


            return QWidget::event(event);






            share|improve this answer























            • How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

              – DevilGale
              Nov 14 '18 at 21:41











            • @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

              – eyllanesc
              Nov 15 '18 at 2:07
















            1














            Use QApplication::notify



            bool QCustomCombo::event(QEvent * event)

            if(event->type() == QEvent::KeyPress)

            QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
            if(keyEvent->key() == Qt::Key_Tab)

            qApp->notify(m_lineEdit, event);
            return true;


            return QWidget::event(event);






            share|improve this answer























            • How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

              – DevilGale
              Nov 14 '18 at 21:41











            • @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

              – eyllanesc
              Nov 15 '18 at 2:07














            1












            1








            1







            Use QApplication::notify



            bool QCustomCombo::event(QEvent * event)

            if(event->type() == QEvent::KeyPress)

            QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
            if(keyEvent->key() == Qt::Key_Tab)

            qApp->notify(m_lineEdit, event);
            return true;


            return QWidget::event(event);






            share|improve this answer













            Use QApplication::notify



            bool QCustomCombo::event(QEvent * event)

            if(event->type() == QEvent::KeyPress)

            QKeyEvent * keyEvent = static_cast<QKeyEvent *>(event);
            if(keyEvent->key() == Qt::Key_Tab)

            qApp->notify(m_lineEdit, event);
            return true;


            return QWidget::event(event);







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 14 '18 at 20:46









            Serhiy KulishSerhiy Kulish

            1524




            1524












            • How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

              – DevilGale
              Nov 14 '18 at 21:41











            • @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

              – eyllanesc
              Nov 15 '18 at 2:07


















            • How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

              – DevilGale
              Nov 14 '18 at 21:41











            • @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

              – eyllanesc
              Nov 15 '18 at 2:07

















            How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

            – DevilGale
            Nov 14 '18 at 21:41





            How do I get access to qApp functions? I tried QCustomCombo : private QApplication, but that breaks my connect() lines. The QCombo is located inside a mainwindow.cpp created by a main.cpp (main.cpp is where I have QApplication instance).

            – DevilGale
            Nov 14 '18 at 21:41













            @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

            – eyllanesc
            Nov 15 '18 at 2:07






            @DevilGale it is not necessary to inherit, just include the header: #include <QApplication>. QApplication::instance() is a singleton that can be used with the qApp macro.

            – eyllanesc
            Nov 15 '18 at 2:07














            1















            I want when an event passed to QComboBox it will be passed to the
            QComboBox->lineEdit().




            installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *) method gets called, object A's eventFilter(QObject *, QEvent *) method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).



            You can use that so that your CustomCombo can see and react to events that would otherwise go directly to the `QComboBox.






            share|improve this answer



























              1















              I want when an event passed to QComboBox it will be passed to the
              QComboBox->lineEdit().




              installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *) method gets called, object A's eventFilter(QObject *, QEvent *) method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).



              You can use that so that your CustomCombo can see and react to events that would otherwise go directly to the `QComboBox.






              share|improve this answer

























                1












                1








                1








                I want when an event passed to QComboBox it will be passed to the
                QComboBox->lineEdit().




                installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *) method gets called, object A's eventFilter(QObject *, QEvent *) method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).



                You can use that so that your CustomCombo can see and react to events that would otherwise go directly to the `QComboBox.






                share|improve this answer














                I want when an event passed to QComboBox it will be passed to the
                QComboBox->lineEdit().




                installEventFilter() is your friend here. It allows object A to install an event filter on another object B, so that before object B's event(QEvent *) method gets called, object A's eventFilter(QObject *, QEvent *) method will be called first, so that object A can decide how to handle the event (and whether or not the event should be passed on to object B afterwards).



                You can use that so that your CustomCombo can see and react to events that would otherwise go directly to the `QComboBox.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 1:56









                Jeremy FriesnerJeremy Friesner

                39.5k1080162




                39.5k1080162



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305074%2fevent-qcombobox-to-custom-qlineedit%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3

                    Museum of Modern and Contemporary Art of Trento and Rovereto