I want to handle the properties key press in CListCtrl in MFC and show a context menu which is already shown with right clicking. How can I do that?
The "properties" key is the "Menu" key.
If you already implemented a context menu then the CListCtrl control must have the focus when you press the "properties" key.
Or alternatively, the main window can watch key messages and notify the control.
Related
In Lazarus, I want to programmatically delete a menu item (say under the File menu) during runtime. The user will open the File menu to list all its items, then use the arrow keys to go to a specific (deletable) item, like a recently used file, and press Del key to delete that menu item from the File menu.
How can I capture the event of Del key being pressed while a specific menu item is selected (highlighted) by the user?
Please note that I am coding for both Windows and Linux (GTK2) at the same time. So, I would need a "standard" (Lazarus-way of) solution that will work on both systems: Suggested Windows-related answers are not appropriate in my case.
I have a QMainWindow with a menubar. I need that menu to be focused by default and the user navigate through the menu.
By default it is required to press the Alt key to jump to the menu bar. I've tried to simulate the Alt key in QMainWindow constructor, but it doesn't work :
QKeyEvent *ev = new QKeyEvent(QEvent::KeyPress,Qt::Key_Alt,Qt::NoModifier);
QCoreApplication::postEvent(qApp->focusWindow(),ev);
Also I've tried to get focus to the menu by setFocus() member function of QMenu and it doesn't work either.
How can I make the menubar focused by default so that the user can navigate through the menu from beginning without the need to press the Alt key?
I want to see how to make it in Gtk2 (e.g. C++). Does gtk2 has ability to set event which is called, when top menu item is clicked?
E.g. topmenu may be "File Edit Help". When "Edit" clicked (Alt+E key too) I want that event is called (event sets checkmarks for menu items in Edit).
How to do it.
You can "trap" them with activate-current. As most of the widgets, they have an activated signal handler.
My CListCtrl (Report View, single column) ignores item selection when there's another control behind the CListCtrl. It's as if the click passes through to the control BEHIND the CListCtrl.
Selection is fine if the list item isn't on top of another dialog-box item.
It's baffling because the CListCtrl's z order is ABOVE these other controls. Can anyone suggest something I could try to make the CListCtrl accept a click even when there's another overlapped control? Thanks!
User Spy++ to check the message flow. And to check if another control is above your control! Maybe there is something wrong with you´r z-order even if you think that the control is above. Also check if you overwrote WM_NCHITTEST
I created the shortcut events, such as:
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
But now I would like to show "Ctrl+Q" in the menu entry here:
How do I do that? I don't seem to find a way to do that in Qt Creator.
You can set the shortcut keys in the QtDesigner in the 'Action Editor' (Tab at the bottom, the 'Signal/Slot Editor' tab is selected by default).
Here all defined QActions are listed. A double click on a field in the 'shortcut' column will open the wanted dialog.
This will add the shortcut to the QAction (create triggered events) and set it as visibile text, e.g. in the menu entry (only visible in the application, not in QtDesigner).
In the 'Property Editor' are more options for the 'shortcuts' (e.g. make them translatable).
Generally you would use QAction class for this, so you would have a QMenu to which you will add actions, in your case CLOSE. Then you can use SetShortcut to add "CTRL + Q" in menu.
pNewAction->setShortcut(QString(strAccel.c_str()));
where pNewAction is of type QAction.