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. QSpinBox-How to make it loose focus when I click somewhere outside the QSpinBox.
QtWS25 Last Chance

QSpinBox-How to make it loose focus when I click somewhere outside the QSpinBox.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 2.8k 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.
  • L Offline
    L Offline
    Luna
    wrote on last edited by aha_1980
    #1

    Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?

    I'd like my QSpinBox to loose focus and trigger valueChanged when the user click somewhere outside the QSpinBox.
    This is usually the normal way to handle focus, so I don't understand why it's not using this way as default with QSpinBox.

    Now the focus is only lost when I click on another button, or another QSpinBox, but not when clicking my QWidget.
    Is there a way to force this behavior?
    Thanks!

    raven-worxR jsulmJ 2 Replies Last reply
    0
    • L Luna

      Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?

      I'd like my QSpinBox to loose focus and trigger valueChanged when the user click somewhere outside the QSpinBox.
      This is usually the normal way to handle focus, so I don't understand why it's not using this way as default with QSpinBox.

      Now the focus is only lost when I click on another button, or another QSpinBox, but not when clicking my QWidget.
      Is there a way to force this behavior?
      Thanks!

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

      @Luna
      this is a question of your widget hierarchy.
      When you click outside your widget the click event will be propagated to the next possible widget. If a widget is found which accepts focus on mouse clicks the focus is transferred which will lead to an focus-out event on your spinbox.

      You may want to try to set the focus policy (make it accept focus) on your window / root-widget.
      Did you set any special focus related stuff on other widgets in your application?

      --- 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
      • L Luna

        Re: QSpinBox - Clicking outside of the QSpinBox to trigger valueChanged?

        I'd like my QSpinBox to loose focus and trigger valueChanged when the user click somewhere outside the QSpinBox.
        This is usually the normal way to handle focus, so I don't understand why it's not using this way as default with QSpinBox.

        Now the focus is only lost when I click on another button, or another QSpinBox, but not when clicking my QWidget.
        Is there a way to force this behavior?
        Thanks!

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

        @Luna This is normal behaviour: you need to click on other widget which accepts focus, if you click on some empty space in your app the focus will stay where it is.

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

        mrjjM 1 Reply Last reply
        2
        • jsulmJ jsulm

          @Luna This is normal behaviour: you need to click on other widget which accepts focus, if you click on some empty space in your app the focus will stay where it is.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          You can set focusPolicy to ClickFocus for your widget.
          http://doc.qt.io/qt-5/qwidget.html#focusPolicy-prop
          Then QSpinBox will lose focus if clicking on your widget.

          update: Ah, raven-worx already explained this :)

          1 Reply Last reply
          2

          • Login

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