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. [Resolved] How can I set the focus on my application at startup
Forum Updated to NodeBB v4.3 + New Features

[Resolved] How can I set the focus on my application at startup

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 3.3k 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.
  • C Offline
    C Offline
    code_fodder
    wrote on last edited by
    #1

    Hi There,

    I am trying to start an app on linux (or even windows) that when run should have focus and hide the mouse. My program does this ok until I hide the mouse... when I hide the mouse the app no longer gets focus!

    Here is the code:

    @
    #include <QApplication>
    #include <QThread>
    #include <stdlib.h>

    int main(int argc, char *argv[])
    {
    // Create the app
    QApplication app(argc, argv);

    // Hide the pointer - IF I UN-COMMENT THIS I LOSE FOCUS AT STARTUP.
    //app.setOverrideCursor( QCursor( Qt::BlankCursor ) );
    
    // Create main window
    MainWindow *window = new MainWindow;
    
    // Set up the UI and execute the App
    window->show();
    app.exec&#40;&#41;;
    
    // tidy up
    delete(window);
    return 0;
    

    }
    @

    You can see my comment where if I un-comment my code to hide the mouse then when the app starts it does not have focus....

    What do I need to do here?
    Thanks

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on last edited by
      #2

      What if you just call the next code in your MainWindow constructor:
      @setCursor(Qt::BlankCursor);@

      I've just tested it and It worked fine, with no focus lost. Have you tried this already? :)

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        code_fodder
        wrote on last edited by
        #3

        Hi There,

        Yes, I did try something like this, but it did not work for me in all cases. It works if I make a PC app and run it on the PC, perhaps as you have done as well, but it somehow fails to work on my embedded touch screen app.

        I am starting to figure that it may be a difference of the OS/Touchscreen.

        I ended up having to use:
        @
        #include <QWSServer>
        :
        QApplication app(argc, argv);
        QWSServer::setCursorVisible(false);
        @
        in main.cpp just after my app is created. I wanted to avoid bringing in more libraries, but I was un-able to get to the route of the cause :(

        Still, this works nicely, seems to be a "more powerful" way of controlling the mouse (and other QWS things which I have not yet looked at).

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on last edited by
          #4

          I hope it solved your problem. Anyway, did you check the "Paint Touch" (or something like that) demo that comes with Qt 4.81? The're basically implementig a classic Paint for touch devices, I'm pretty sure there was no mouse in there, so you may want to look at it.

          (8) Just live your life blind like me (8)

          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