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. Multiple LineEdits focus issues
QtWS25 Last Chance

Multiple LineEdits focus issues

Scheduled Pinned Locked Moved Solved General and Desktop
qlineeditfocus issuefocusip editorcustomplugin
7 Posts 4 Posters 3.3k Views
  • 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.
  • Sh1gsS Offline
    Sh1gsS Offline
    Sh1gs
    wrote on last edited by
    #1

    Hello,

    I am creating an IP Editor custom plugin using 4 QLineEdits. I am using 4 LineEdits so that the end user has the ability to edit each input mask individually. I have set them all to ClickFocus. However, my issue is that, say the IP Editor is completely empty and a user clicks on the third input mask, how do I force the cursor and focus to be on the first input mask instead? Would it be easier to set the latter 3 to read only at startup? Or is there a better way of handling this?

    Thank you

    jsulmJ 1 Reply Last reply
    0
    • Vinod KuntojiV Offline
      Vinod KuntojiV Offline
      Vinod Kuntoji
      wrote on last edited by
      #2

      @Sh1gs ,
      connect(m_LineEdit3, SIGNAL(textChanged(QString)),this,SLOT(enableLineEditIP(QString)));

      SLOT:
      void Widget :: enableLineEditIP(QString str) {
      if(m_LineEditIP->text().isEmpty()) {
      m_LineEdit3->clear();
      m_LineEditIP->setFocus();
      }
      }

      C++, Qt, Qt Quick Developer,
      PthinkS, Bangalore

      1 Reply Last reply
      2
      • Sh1gsS Sh1gs

        Hello,

        I am creating an IP Editor custom plugin using 4 QLineEdits. I am using 4 LineEdits so that the end user has the ability to edit each input mask individually. I have set them all to ClickFocus. However, my issue is that, say the IP Editor is completely empty and a user clicks on the third input mask, how do I force the cursor and focus to be on the first input mask instead? Would it be easier to set the latter 3 to read only at startup? Or is there a better way of handling this?

        Thank you

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

        @Sh1gs I wouldn't do it like this. Instead I would disable all 3 line edits on the right side and kepp only the first one on the left side enabled. As soon as the user enters a number into the left line edit I would activate the next line edit and so on.
        Your solution would irritate the user: he/she clicks an line edit but the focus goes to another one. This is unexpected behaviour.

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

        Sh1gsS 1 Reply Last reply
        1
        • jsulmJ jsulm

          @Sh1gs I wouldn't do it like this. Instead I would disable all 3 line edits on the right side and kepp only the first one on the left side enabled. As soon as the user enters a number into the left line edit I would activate the next line edit and so on.
          Your solution would irritate the user: he/she clicks an line edit but the focus goes to another one. This is unexpected behaviour.

          Sh1gsS Offline
          Sh1gsS Offline
          Sh1gs
          wrote on last edited by
          #4

          Thank you @Vinod-Kuntoji , unfortunately this method did not work for me.

          @jsulm I tried this method yesterday after submitting the forum and it does work, it just requires more coding to enable the other 3 edits. I was just hoping there was a cleaner way, almost like lineedit->resetcursorposition(int).

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            @Sh1gs

            This topic might be of interest to you , since it looks like your problem setting.

            Eddy

            Qt Certified Specialist
            www.edalsolutions.be

            Sh1gsS 1 Reply Last reply
            1
            • EddyE Eddy

              @Sh1gs

              This topic might be of interest to you , since it looks like your problem setting.

              Eddy

              Sh1gsS Offline
              Sh1gsS Offline
              Sh1gs
              wrote on last edited by
              #6

              Thanks @Eddy, I've seen this topic and used a lot of the methodologies from it already.

              I will go ahead and mark this topic as solved. I went ahead and set the last 3 LineEdits to readOnly at startup and then change them accordingly as numbers are entered.

              Thank you everyone

              1 Reply Last reply
              1
              • EddyE Offline
                EddyE Offline
                Eddy
                wrote on last edited by
                #7

                Thanks for posting your solution.

                Happy coding.

                Qt Certified Specialist
                www.edalsolutions.be

                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