PDA

View Full Version : Is there some way to block shortcuts from keyboard temporary?



pir
21st February 2007, 11:52
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

wysota
21st February 2007, 12:06
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.

pir
23rd February 2007, 09:21
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

aamer4yu
23rd February 2007, 09:50
Will this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-keyboard-shortcuts-problem-1639.html) be useful to you ??


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

pir
23rd February 2007, 10:12
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

pir
23rd February 2007, 10:23
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