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. Hiding the cursor on QLineEdit
Forum Updated to NodeBB v4.3 + New Features

Hiding the cursor on QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 894 Views 4 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.
  • J Offline
    J Offline
    Jonikles
    wrote on 31 May 2023, 13:37 last edited by
    #1

    Pretty much the title. I have a QLineEdit and I want whenever the user clicks away on something else to stop the focus on the QLineEdit. If that's not possible then if you guys have any idea on how to completely remove the cursor in the first place that would also work.
    Thanks!

    J 1 Reply Last reply 31 May 2023, 14:18
    0
    • J Jonikles
      31 May 2023, 19:27

      @Pl45m4 oh yeah whenever I click on a different widget it disappears that's a brain fart on my end haha. But it doesn't work when clicking on a QFrame.. any way to change that?
      BTW, if it helps in general:
      Windows 10, QT 6.5, default QLineEdit.

      M Offline
      M Offline
      mpergand
      wrote on 31 May 2023, 20:25 last edited by
      #8

      @Jonikles said in Hiding the cursor on QLineEdit:

      But it doesn't work when clicking on a QFrame.. any way to change that?

      call :
      QFrame::setFocusPolicy(Qt::ClickFocus)

      J 1 Reply Last reply 31 May 2023, 21:29
      3
      • J Jonikles
        31 May 2023, 13:37

        Pretty much the title. I have a QLineEdit and I want whenever the user clicks away on something else to stop the focus on the QLineEdit. If that's not possible then if you guys have any idea on how to completely remove the cursor in the first place that would also work.
        Thanks!

        J Online
        J Online
        JonB
        wrote on 31 May 2023, 14:18 last edited by
        #2

        @Jonikles said in Hiding the cursor on QLineEdit:

        I have a QLineEdit and I want whenever the user clicks away on something else to stop the focus on the QLineEdit.

        When you "click away to something else" that should remove the focus on the QLineEdit, and stop showing the cursor.

        J P 2 Replies Last reply 31 May 2023, 17:41
        1
        • J JonB
          31 May 2023, 14:18

          @Jonikles said in Hiding the cursor on QLineEdit:

          I have a QLineEdit and I want whenever the user clicks away on something else to stop the focus on the QLineEdit.

          When you "click away to something else" that should remove the focus on the QLineEdit, and stop showing the cursor.

          J Offline
          J Offline
          Jonikles
          wrote on 31 May 2023, 17:41 last edited by Jonikles
          #3

          @JonB like automatically? if that's what you're saying then that is not what's happening for me. It's like this:
          Until you start editing - no focus obviously, but once you do it never goes away unless I focus onto a different QEditLine but that's no solution.

          M 1 Reply Last reply 31 May 2023, 18:39
          0
          • J Jonikles
            31 May 2023, 17:41

            @JonB like automatically? if that's what you're saying then that is not what's happening for me. It's like this:
            Until you start editing - no focus obviously, but once you do it never goes away unless I focus onto a different QEditLine but that's no solution.

            M Offline
            M Offline
            mpergand
            wrote on 31 May 2023, 18:39 last edited by
            #4

            @Jonikles
            Implement an event filter on the parent window then,
            when a click occurred on an other button, call clearFocus() on your line edit.

            1 Reply Last reply
            3
            • J JonB
              31 May 2023, 14:18

              @Jonikles said in Hiding the cursor on QLineEdit:

              I have a QLineEdit and I want whenever the user clicks away on something else to stop the focus on the QLineEdit.

              When you "click away to something else" that should remove the focus on the QLineEdit, and stop showing the cursor.

              P Offline
              P Offline
              Pl45m4
              wrote on 31 May 2023, 18:58 last edited by Pl45m4
              #5

              @JonB said in Hiding the cursor on QLineEdit:

              When you "click away to something else" that should remove the focus on the QLineEdit, and stop showing the cursor.

              Depends on what/where clicking elsewhere is, I guess.

              If you ( @Jonikles ) click/focus another widget or window, the cursor should definitely disappear.
              Can you confirm that?!

              What OS are you on? Which Qt version? Are we dealing with a default QLineEdit or any re-implementation or subclass?

              But this sounds so weird, that it is too obvious to be a bug that stayed in for a longer time, no matter what Qt version.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              J 1 Reply Last reply 31 May 2023, 19:27
              0
              • P Pl45m4
                31 May 2023, 18:58

                @JonB said in Hiding the cursor on QLineEdit:

                When you "click away to something else" that should remove the focus on the QLineEdit, and stop showing the cursor.

                Depends on what/where clicking elsewhere is, I guess.

                If you ( @Jonikles ) click/focus another widget or window, the cursor should definitely disappear.
                Can you confirm that?!

                What OS are you on? Which Qt version? Are we dealing with a default QLineEdit or any re-implementation or subclass?

                But this sounds so weird, that it is too obvious to be a bug that stayed in for a longer time, no matter what Qt version.

                J Offline
                J Offline
                Jonikles
                wrote on 31 May 2023, 19:27 last edited by
                #6

                @Pl45m4 oh yeah whenever I click on a different widget it disappears that's a brain fart on my end haha. But it doesn't work when clicking on a QFrame.. any way to change that?
                BTW, if it helps in general:
                Windows 10, QT 6.5, default QLineEdit.

                P M 2 Replies Last reply 31 May 2023, 19:58
                0
                • J Jonikles
                  31 May 2023, 19:27

                  @Pl45m4 oh yeah whenever I click on a different widget it disappears that's a brain fart on my end haha. But it doesn't work when clicking on a QFrame.. any way to change that?
                  BTW, if it helps in general:
                  Windows 10, QT 6.5, default QLineEdit.

                  P Offline
                  P Offline
                  Pl45m4
                  wrote on 31 May 2023, 19:58 last edited by Pl45m4
                  #7

                  @Jonikles said in Hiding the cursor on QLineEdit:

                  But it doesn't work when clicking on a QFrame

                  Clicking on a QFrame or plain QWidget doesn't direct the focus to them per default. It triggers MouseClick / -ReleaseEvents, but the focus stays at QLineEdit, therefore the cursor is staying visible. Same for any other widget, where you can select something. Selected QListWidgetItems stay selected, when clicking somewhere on an empty QWidget space (QFrame is also a QWidget).

                  To work around that, try what @mpergand suggested. Install an eventFilter and move the focus where you want it to be, when your QLineEdit has focus and your QFrame is clicked.

                  [Edit: @mpergand 's new solution works even better ;-) ]


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  1
                  • J Jonikles
                    31 May 2023, 19:27

                    @Pl45m4 oh yeah whenever I click on a different widget it disappears that's a brain fart on my end haha. But it doesn't work when clicking on a QFrame.. any way to change that?
                    BTW, if it helps in general:
                    Windows 10, QT 6.5, default QLineEdit.

                    M Offline
                    M Offline
                    mpergand
                    wrote on 31 May 2023, 20:25 last edited by
                    #8

                    @Jonikles said in Hiding the cursor on QLineEdit:

                    But it doesn't work when clicking on a QFrame.. any way to change that?

                    call :
                    QFrame::setFocusPolicy(Qt::ClickFocus)

                    J 1 Reply Last reply 31 May 2023, 21:29
                    3
                    • M mpergand
                      31 May 2023, 20:25

                      @Jonikles said in Hiding the cursor on QLineEdit:

                      But it doesn't work when clicking on a QFrame.. any way to change that?

                      call :
                      QFrame::setFocusPolicy(Qt::ClickFocus)

                      J Offline
                      J Offline
                      Jonikles
                      wrote on 31 May 2023, 21:29 last edited by
                      #9

                      @mpergand @Pl45m4 amazing! thank you both :D

                      1 Reply Last reply
                      0
                      • J Jonikles has marked this topic as solved on 31 May 2023, 21:30
                      • J Jonikles has marked this topic as unsolved on 31 May 2023, 21:30
                      • J Jonikles has marked this topic as solved on 31 May 2023, 21:30

                      8/9

                      31 May 2023, 20:25

                      • Login

                      • Login or register to search.
                      8 out of 9
                      • First post
                        8/9
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved