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. Show focus highlight when open a window
Forum Updated to NodeBB v4.3 + New Features

Show focus highlight when open a window

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 901 Views 1 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I am playing with the widget focus. I want to navigate through the buttons with tab key. I put the tab order but I need to show the highlight stylesheet when I open the window in the first button.

    I tried with ui->button->setFocus() in the constructor but qt doesn't highlight it.

    How can I do it?

    Thank you very much!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      As docs says
      https://doc.qt.io/qt-5/qwidget.html#setFocus
      "Be aware that if the widget is hidden, it will not accept focus until it is shown."

      so you cannot do it in ctor as its hidden there.

      You can use the forms ShowEvent.

      ivanicyI 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        As docs says
        https://doc.qt.io/qt-5/qwidget.html#setFocus
        "Be aware that if the widget is hidden, it will not accept focus until it is shown."

        so you cannot do it in ctor as its hidden there.

        You can use the forms ShowEvent.

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        @mrjj The button isn't hidden. I tried with the showEvent but it doesn't work. The problem is the first time, when I push tab button, the next button highlights correctly. The first button doesn't highlight at first time.

        mrjjM 1 Reply Last reply
        0
        • ivanicyI ivanicy

          @mrjj The button isn't hidden. I tried with the showEvent but it doesn't work. The problem is the first time, when I push tab button, the next button highlights correctly. The first button doesn't highlight at first time.

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

          @ivanicy
          Well, the button is hidden in the constructor as it not yet shown. That was my main point.

          Ok, it normally works fine with showEvent.
          did you try setFocus with Qt::TabFocusReason ?

          ivanicyI 1 Reply Last reply
          2
          • mrjjM mrjj

            @ivanicy
            Well, the button is hidden in the constructor as it not yet shown. That was my main point.

            Ok, it normally works fine with showEvent.
            did you try setFocus with Qt::TabFocusReason ?

            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @mrjj I have tried it but it doesn't work.

            mrjjM 1 Reply Last reply
            0
            • ivanicyI ivanicy

              @mrjj I have tried it but it doesn't work.

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

              @ivanicy
              ok.
              when you say dont work. what does it mean.
              the button does get focus but the stylesheet is not triggering
              or in which "doesn't work."

              ivanicyI 1 Reply Last reply
              0
              • mrjjM mrjj

                @ivanicy
                ok.
                when you say dont work. what does it mean.
                the button does get focus but the stylesheet is not triggering
                or in which "doesn't work."

                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #7

                @mrjj It's always the same problem. The button has the focus, but doesn't show the focus stylesheet

                mrjjM 1 Reply Last reply
                0
                • ivanicyI ivanicy

                  @mrjj It's always the same problem. The button has the focus, but doesn't show the focus stylesheet

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

                  @ivanicy

                  so either it don't really have the focus or there is a bug in stylesheet handling or in user code.

                  Do you have a minimal example showing this behavior?

                  1 Reply Last reply
                  1

                  • Login

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