Results 1 to 6 of 6

Thread: Is there some way to block shortcuts from keyboard temporary?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Is there some way to block shortcuts from keyboard temporary?

    Hi

    I have a lot of menu options that can be activated by using keys on the keyboard. When I open a saveFileDialog to save a file, these actions is triggered when the user tries to write the wanted name to save the file as. Is there some convenient way to block all keyboard shortcuts until the saveFileDialog is closed?

    I've tried to useBlockSignals and it does not solve the problem. The FileDialog is opened from a QMainWindow and the shortcuts is placed in the main menu and other menus.

    thanks
    pir

  2. #2
    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: Is there some way to block shortcuts from keyboard temporary?

    I think you'd have to subclass QApplication and reimplement some method responsible for delivering events, but it may be a complex task. I suggest you look for another solution You could remove the shortcuts not using any modifier keys and reimplement keyPressEvent for a particular widget instead triggering appropriate actions. You could then enable/disable those "shortcuts" on the fly. Furthermore the shortcuts will only be active when the widget has keyboard focus, which is probably what you want.

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Is there some way to block shortcuts from keyboard temporary?

    Hi!

    Thanks for you answer. But one thing that made me think is that it is only the shortcuts in the menubar in the Main window that is fired. I have another menubar in a frame that lies in the main window. These shortcuts are not fired. I am using MacOSX and I don't think that I've hade these problems at all when I used the program on Linux. Could it be that there is a problem with Qt and Mac on this matter?

    I've reubuilt the main window with QDesigner since it is easier to handle the menu layout in this way. So I would rather not hardcode the shortcuts by hand. But I understand what you're saying, I'm just hoping that I can find some way aroud this without doing it.

    thanx
    pir

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is there some way to block shortcuts from keyboard temporary?

    Will this thread be useful to you ??


    also will making the dialog as modal help you ?? am not clear whats ur sequence of saving the data..

  5. #5
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Is there some way to block shortcuts from keyboard temporary?

    Hi!

    I'm looking on the thread right now. But since you've asked I'll explain the save sequence. It's verry simple:
    I open one of the QFileDialog::getFileName(). I think it is modal. The menu is greyed. The other shortcuts in the menu is turned off... that is, I can't quit the app with Ctrl+Q if the save dialog is open. But the menu steals the "W" pressed key when I try to write a name containing a 'W'...

    I don't know yet if the thread is to any help. I'm not sure how I would use it... but thanks anyway. As I said before, I'm looking at it right now.

    thanx
    pir

  6. #6
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Is there some way to block shortcuts from keyboard temporary?

    Hi again!

    I've solved the problem. When I called QFileDialog::getFileName() I put the QMainWindow as parent for it... but if I set the QMainWindow->menuBar() as the parent, all the events are blocked in the menuBar.

    thanks for all the help, it is often when I have to explain the problem that makes me rethink and automatically finds the solution.
    pir

Similar Threads

  1. Keyboard shortcuts problem.
    By Lemming in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2006, 16:12

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.