Results 1 to 7 of 7

Thread: Grabbing ahold of the focus, screen, keyboard and their soul

  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Grabbing ahold of the focus, screen, keyboard and their soul

    Ok, I've got an application that needs to grab ahold of EVERYTHING until a user does the correct thing. I need it to pop back up to the foreground if someone minimizes it or clicks on another window. The first thing it needs to do is explicitly pop to the front.

    Thoughts suggestions? And warning. I'm a Qt newbie who just got handed this project cause the previous guy left.

  2. #2
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    I sense something evil here.... Ok, it's possible that you could have a legit use for this, but this smells of bad user interface design.

    Save yourself a whole lot of trouble by making the window maximized, always on top, and without a window frame (have a look at Window flags for QWidget (in the constructor)). This removes the ability to click on most apps already. Of course, the user could still get around it if they really wanted to, but you can prevent a lot of that with some event capturing (QWidget::leaveEvent(), etc)

  3. #3
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    Naw... Nothing evil here. The reason we want to take over is that the system will be in an unusable state at the time. The target users are people with barely any training using the machine. So we need to be as bloody obvious and as bulletproof as possible. Hence trying to take away as many options as possible. Basically, we're telling them when to change the printer paper. The only reason we want the message is because we've already had users of the test app complain that the machine stopped printing and just sat there. We implemented a system message to their TTY to tell them to change the paper... And some of them still ignored it. Not allowing them to do anything else until the fix the problem... Sadly seems to be the only thing that might work.

    I'm going to try first with a QmessageBox and see how they react to that. We might not have to go crazy with the not letting them do anything... But we'll see how the tests go

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    If your application runs under KDE, you might want to reuse its functionality for locking the screen using DCOP interface... If that's not an option, maybe you should take a look at that part of KDE sources which actually implements the lock.

  5. #5
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    Qt Code:
    1. QApplication x11EventFilter ( XEvent* e )
    To copy to clipboard, switch view to plain text mode 
    function may do what you want. But this time you need to have a programming context about X11 functions. when your application's window lost focus then your window also gets an event.

    you may chance to decide which events you can hook. possible focus lost event is most appropriate for you.

    i tested this function when a window lost focus then XEvent's type member gets the value of 10.

    Qt Code:
    1. //e->type == 10
    To copy to clipboard, switch view to plain text mode 

    but unfortunately, i don't know how to make a window to be on top and visible over other windows.

    raise(), setActiveWindow(), show() functions don't guaranty the visibility of the window. But blink effect appears on menu bar instead

  6. #6
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    To make a widget that is always on top:
    QWidget::setWindowFlags(Qt::WindowStaysOnTopHint)
    You might also need to pass Qt::X11BypassWindowManagerHint for this to work.

    for no frame (and therefore no maximize/minimize/close buttons)
    Qt::FramelessWindowHint

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grabbing ahold of the focus, screen, keyboard and their soul

    In this particular situation I would just show the widget full screen instead of forcing it on top.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.