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. Focus
Forum Updated to NodeBB v4.3 + New Features

Focus

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 780 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.
  • O Offline
    O Offline
    Oumayma
    wrote on last edited by
    #1

    Hello, I would like to control the focus of my application, when it is executed that the application has the focus and when I am outside the application, I lose it and all the processes stop their execution.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I'm not sure I understand if you want to actually control the focus or get a notification when it changes.

      For the second case take a look at focusWindowChanged signal. You will get your app's window that receives focus or nullptr if your app looses it.

      O 2 Replies Last reply
      2
      • Chris KawaC Chris Kawa

        I'm not sure I understand if you want to actually control the focus or get a notification when it changes.

        For the second case take a look at focusWindowChanged signal. You will get your app's window that receives focus or nullptr if your app looses it.

        O Offline
        O Offline
        Oumayma
        wrote on last edited by
        #3

        @Chris-Kawa Both things, both controlling the focus and being notified of the change

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then for notification you can use the signal I mentioned, but moving focus away from your app will be different for different platforms. Also that's not something applications often do and it can be annoying to users if applications change focus without their actions. What's your use case?

          O 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            Then for notification you can use the signal I mentioned, but moving focus away from your app will be different for different platforms. Also that's not something applications often do and it can be annoying to users if applications change focus without their actions. What's your use case?

            O Offline
            O Offline
            Oumayma
            wrote on last edited by
            #5

            @Chris-Kawa For windows and android

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No, I meant why do you need to manually change focus between apps.

              O 1 Reply Last reply
              0
              • Chris KawaC Chris Kawa

                No, I meant why do you need to manually change focus between apps.

                O Offline
                O Offline
                Oumayma
                wrote on last edited by
                #7

                @Chris-Kawa Because my application is a text editor for people with functional diversity and it has very specific configurations and I need to have control of the focus.

                1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  I'm not sure I understand if you want to actually control the focus or get a notification when it changes.

                  For the second case take a look at focusWindowChanged signal. You will get your app's window that receives focus or nullptr if your app looses it.

                  O Offline
                  O Offline
                  Oumayma
                  wrote on last edited by
                  #8

                  @Chris-Kawa Could you provide me with an example of the operation of focusWindowChanged.

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    There's not much to show. It's just a regular Qt signal on the application object, but here's a simple example:

                    #include <QApplication>
                    #include <QLabel>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        QLabel label;
                        label.show();
                    
                        QObject::connect(&a, &QGuiApplication::focusWindowChanged, [&](QWindow* window)
                        {
                            label.setText(window ? "App has focus" : "App doesn't have focus");
                        });
                    
                        return a.exec();
                    }
                    
                    O 1 Reply Last reply
                    1
                    • Chris KawaC Chris Kawa

                      There's not much to show. It's just a regular Qt signal on the application object, but here's a simple example:

                      #include <QApplication>
                      #include <QLabel>
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                      
                          QLabel label;
                          label.show();
                      
                          QObject::connect(&a, &QGuiApplication::focusWindowChanged, [&](QWindow* window)
                          {
                              label.setText(window ? "App has focus" : "App doesn't have focus");
                          });
                      
                          return a.exec();
                      }
                      
                      O Offline
                      O Offline
                      Oumayma
                      wrote on last edited by
                      #10

                      @Chris-Kawa Thanks this has helped me, and on the subject of changing the focus you know how I could do 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