Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. No widgets get focus
QtWS25 Last Chance

No widgets get focus

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 3 Posters 5.5k 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.
  • J Offline
    J Offline
    JohnGraham
    wrote on last edited by
    #1

    Hi,

    I'm developing an application for an embedded device, and want to be able to let the user use a USB keyboard to edit text in QLineEdit objects. However, none of my widgets are receiving focus!

    Another prototype-style application I made on the same device has no problem with it - the text cursor appears and keyboard entries get treated just like on-screen entries (which use insert(QString)). But in my new application, this just doesn't happen - none of my widgets get focus. I initially had a problem with buttons getting focus (which makes them look weird) so I set all of them to have the Qt::NoFocus policy, but now even when I remove these statements, still nothing gets focus, and I have no idea why.

    My main class is a QMainWindow, whose central widget is a QStackedWidget, if that makes any difference.

    Anybody got any ideas?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      does the parent widgets of the line edit have the noFocus policy set?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JohnGraham
        wrote on last edited by
        #3

        I just left them all at their defaults initially. However, even if I make sure they're all set to StrongFocus by doing this in the constructor:

        @
        QWidget *p = ui.lineEdit;
        do {
        p->setFocusPolicy(Qt::StrongFocus);
        } while (p = p->parentWidget());
        @

        There's still no joy.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JohnGraham
          wrote on last edited by
          #4

          Additionally, I do this after construction-time and printed the objectName of each widget I call setFocusPolicy on, and it definitely goes right up to the top QMainWindow.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JohnGraham
            wrote on last edited by
            #5

            A curious thing - I now have another main window that takes over the screen. When I hide it, the widgets in the original window (that did not have focus before) can now all have focus as normal!

            Anybody got any idea what's going on here, and how I get back to a focusable state without having to bring up this other window?

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Fuzzbender
              wrote on last edited by
              #6

              Could it be that your original window is for some unknown reason (hard to say why without seeing the whole application code) not active? Try calling setActiveWindow() for it?

              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