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. Regarding QLineEdit , of how to know the focus of lineedit currently
Forum Updated to NodeBB v4.3 + New Features

Regarding QLineEdit , of how to know the focus of lineedit currently

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 7.4k Views 2 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    I have implemented MyLineEdit inherting QLineEdit, and implemented focusevent

    void MyLineEdit::focusInEvent(QFocusEvent *event)
    {
        QLineEdit::focusInEvent(event);
    
        qDebug () << Q_FUNC_INFO <<  "focus on lineedit :>" << endl;
    }
    

    then i have created two lineedit object to enter text, i have text values from another widget having buttons, so how do i know which lineedit objects is in focus so i will append to text from buttons.?.

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    raven-worxR 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      Hi,

      I have implemented MyLineEdit inherting QLineEdit, and implemented focusevent

      void MyLineEdit::focusInEvent(QFocusEvent *event)
      {
          QLineEdit::focusInEvent(event);
      
          qDebug () << Q_FUNC_INFO <<  "focus on lineedit :>" << endl;
      }
      

      then i have created two lineedit object to enter text, i have text values from another widget having buttons, so how do i know which lineedit objects is in focus so i will append to text from buttons.?.

      Thanks,

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Pradeep-Kumar

      1. lineEdit->hasFocus()
      2. QApplication::focusWidget() to get the QWidget which is currently focused

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        k,

        QLineedit has method hasFocus();

        if(m_lineEdit1->hasFocus())
            {
                    m_lineEdit1->setText(value);
            }
            else
            {
                    m_lineEdit2->setText(value);
            }
        

        link of the image where showing to lineedit, and kayboard having buttons,

        https://postimg.org/image/grbqk08wl/

        if i have clicked first lineedit, if i enter the buttons, i am getting values to second lineedit.
        but focus is in First lineedit.

        How can i resolve?.

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        raven-worxR 1 Reply Last reply
        0
        • Pradeep KumarP Pradeep Kumar

          k,

          QLineedit has method hasFocus();

          if(m_lineEdit1->hasFocus())
              {
                      m_lineEdit1->setText(value);
              }
              else
              {
                      m_lineEdit2->setText(value);
              }
          

          link of the image where showing to lineedit, and kayboard having buttons,

          https://postimg.org/image/grbqk08wl/

          if i have clicked first lineedit, if i enter the buttons, i am getting values to second lineedit.
          but focus is in First lineedit.

          How can i resolve?.

          Thanks,

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Pradeep-Kumar
          ok, you didn't mention that the sending widget is in another window.
          You then have to use windowWidget->focusWidget()

          That's the reason why there is the concept of input contexts. But this is out-of-scope i guess. This is a very complex topic and needs quite some research from your side before starting.
          Also you might want to look into the code of the QtVirtualKeyboard module for that.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by Pradeep Kumar
            #5

            i have established signal slot connection from one widget to another widget,
            but only problem i am finding is, which lineedit is in focus and how to append the button text to the lineedit focused.?

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            jsulmJ 1 Reply Last reply
            0
            • Pradeep KumarP Pradeep Kumar

              i have established signal slot connection from one widget to another widget,
              but only problem i am finding is, which lineedit is in focus and how to append the button text to the lineedit focused.?

              Thanks,

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pradeep-Kumar As @raven-worx said use windowWidget->focusWidget() to get the widget which has the focus. But check whether it is one of the line edits.
              To append text it is as easy as

              lineEdit->setText(lineEdit->text() + "NEW TEXT");
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              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