PDA

View Full Version : Context sensitive help



jpn
9th February 2007, 16:10
Hello,

What kind of mechanisms do you people use for building context sensitive helps into Qt applications?

My idea was to create a single application wide shortcut (Qt::ApplicationShortcut). In the slot connected to the shortcut my plan was to act according to the QApplication::focusWidget(). Everything was working smooth until I noticed that modal dialogs prevent the shortcut from getting activated. The shortcut event gets lost somewhere in the event loop run by the modal dialog and the shortcut never gets activated. I would have expected that an application wide shortcut gets activated even when there's a modal dialog running it's own event loop.

Nevertheless, I have already reported the issue to TT. But now what I'm looking for is a decent enough temporary workaround. One not-so-good workaround would be to create a corresponding shortcut for each and every modal dialog. I really wanted to avoid sprinkling the help related code all over the project.

So, just curious, how do you people do it?

wysota
9th February 2007, 20:32
There is QHelpEvent and QWhatsThisClickedEvent and QAssistantClient. If you want to keep all the help related code in one place, I suggest you do it in the application object as all events pass through QCoreApplication. Global coordinates may help you pinpoint the widget under cursor or you may install an event filter somewhere to gather and handle all help events in one place.

Of course the simplest way is just to use What's This architecture.

jpn
9th February 2007, 20:54
First of all, sorry for not being clear enough.

I have "what's this" texts and tool tips set all around, but that's not what I was talking about when referring to "context sensitive help". What I was talking about was indeed about using QAssistantClient as providing some more verbal help.

One could catch for example key press event for F1 at the application level and launch the Assistant and/or switch the page when required. I though creating a QShortcut with key sequence of QKeySequence::HelpContents was the correct cross-platform approach for triggering the help.

All the context sensitive help related code for finding the correct page in the help documentation is already done at application level, in a QApplication subclass. As mentioned earlier, the correct help page for Assistant is determined according to the current widget (or it's parent / grand parents) containing the focus.

The only problem is that the slot containing the help functionality in the QApplication subclass is not triggered whenever a modal dialog is active. Otherwise it's working as desired.

jacek
9th February 2007, 21:23
what I'm looking for is a decent enough temporary workaround. One not-so-good workaround would be to create a corresponding shortcut for each and every modal dialog. I really wanted to avoid sprinkling the help related code all over the project.
How about deriving your dialogs from a custom Dialog class that will be aware of that shortcut? This way the help-handling code would be only in one place.

Other thing you can try are aspects (http://www.aspectc.org/). You could inject that shortcut object into every class you derive from QDialog and still keep the code outside your main sources.

wysota
9th February 2007, 23:27
You can install event filters on those dialogs before exec'ing them. That should allow you to intercept the shortcut even if the main (application) event loop is not running. You could then call the slot yourself.