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. How do I set a window to get focus when the program starts?
Forum Updated to NodeBB v4.3 + New Features

How do I set a window to get focus when the program starts?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 612 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.
  • M Offline
    M Offline
    mirro
    wrote on last edited by
    #1
    Using this QWidget::setFocus()  function is invalid.
    
    jsulmJ JonBJ 2 Replies Last reply
    0
    • M mirro
      Using this QWidget::setFocus()  function is invalid.
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mirro said in How do I set a window to get focus when the program starts?:

      function is invalid

      How is it invalid?
      A window get automatically focus when the app starts.
      Or do you actually mean that you want a specific widget to have focus? This can be done in Designer already.
      Take a look at https://doc.qt.io/qt-5/focus.html, https://doc.qt.io/qt-5/qwidget.html#setTabOrder

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

      M 1 Reply Last reply
      4
      • M mirro
        Using this QWidget::setFocus()  function is invalid.
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @mirro said in How do I set a window to get focus when the program starts?:

        Using this QWidget::setFocus() function is invalid.

        Show the actual line of code where you use it, and what method you are inside when you do so.

        Follow what @jsulm has suggested first. However, I have a dim recollection: depending on your situation, it may be that setFocus() doesn't do anything if called too early (e.g. in a contstructor). You might need to override widget's showEvent(), or do it from installEventFilter(), so that you only set focus once the widget becomes visible. Not sure about this, but may be required.

        1 Reply Last reply
        1
        • jsulmJ jsulm

          @mirro said in How do I set a window to get focus when the program starts?:

          function is invalid

          How is it invalid?
          A window get automatically focus when the app starts.
          Or do you actually mean that you want a specific widget to have focus? This can be done in Designer already.
          Take a look at https://doc.qt.io/qt-5/focus.html, https://doc.qt.io/qt-5/qwidget.html#setTabOrder

          M Offline
          M Offline
          mirro
          wrote on last edited by
          #4

          @jsulm Once the layout is set up, the setFocus invocation is feasible

          jsulmJ 1 Reply Last reply
          0
          • M mirro

            @jsulm Once the layout is set up, the setFocus invocation is feasible

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

            @mirro said in How do I set a window to get focus when the program starts?:

            Once the layout is set up, the setFocus invocation is feasible

            And what is now the problem?

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

            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