I have a app that has items that can contain child items and so on.
Each item has a mouseDown event that i want to be able to use to click and select an item.
The problem is that when i click a child item the parents mouseDown event is also being called.
How do i stop this so the mouseDown event only gets called once or if thats not posible i actually want the function called within the mouseDown event to only get called once.
Here is a jsfiddle to very simply show this. http://jsfiddle.net/rmossuk/W9vmW/1/
If you click no the Click here its mouse down event gets called twice.
You have to return false; in the mouseDown function.
Or you can you use event.stopPropagation(). I updated your fiddle, see http://jsfiddle.net/W9vmW/2/.
There is more informations about how event bubbling in ember works here - http://emberjs.com/guides/view_layer/#toc_event-bubbling
Events will bubble up the view hierarchy until the event reaches the root view. An event handler can stop propagation using the same techniques as normal jQuery event handlers:
return false from the method
event.stopPropagation
Related
My application consists of a tree view with files that the user can click on. Based on the file the preview area will show the appropriate control to display that file. For some files that is a GtkGlArea that is rendering the content. It includes a camera that should be movable using the keyboard and mouse.
When a file is clicked the following happens (inside the event handler of the changed event of the GtkTreeView)
if (mActiveView->needsOpenGL()) {
gtk_widget_show(mGlControl);
gtk_widget_grab_focus(mGlControl);
} else {
gtk_widget_hide(mGlControl);
}
The mGlControl is created using a GtkBuilder that reads my Glade UI template. The control has the flags Visible, Can focus, Application paintable, Double Buffered, Sensitive and the events Pointer Motion, Button Press, Button Release, Key Press, Key Release, Focus Change, Structure
However when an element is clicked in the tree view the focus stays on that item and when I use my keyboard it is reflected in the tree view (using arrow up selects the next item for example).
Is it possible to put the focus on a GtkGlArea?
It turns out the intuition I had after re-reading my posted question was correct. It seems switching focus inside the event handler of the tree view change event was not working. I think the chain of events is probably like this:
Item is clicked
Changed event is handled and delegated -> focus set on the gl control
"Click" event on the item is handled -> focus set on the tree view item
It seems the focus logic for clicking an item is done after the change event is issued.
I adapted my code to look like this:
if (mActiveView->needsOpenGL()) {
gtk_widget_show(mGlControl);
runInMainThread([this]() { gtk_widget_grab_focus(mGlControl); });
} else {
gtk_widget_hide(mGlControl);
}
This is a convenience method:
void MainWindow::runInMainThread(const std::function<void()> &callback) {
g_idle_add(callbacks::mainThreadCallback, new callbacks::FunctionHolder{callback});
}
And should delay it for after the processing of the click event and now the tree view item gets properly defocused.
I have a CDialogEx Class called Properties in which I handle the ON_COMMAND message. Now, ON_COMMAND should get called when I click the menu item ID_EDIT_PROPERTIES (as a submenu from main menu). The event handler wizard wrote that code for me, but when I start the Application the menu item remains grayed out. I've tried to manually activate it by calling EnableMenuItem when ON_UPDATE_COMMAND_UI happens, but to no avail.
Any help would be greatly appreciated.
You just need to understand how menu items enabling/disabling is handled:
If there is neither ON_COMMAND nor ON_UPDATE_COMMAND_UI handler the item is disabled.
If there exists no ON_UPDATE_COMMAND_UI handler but there is an ON_COMMAND one in the currently active document or view (or even the "mainframe"), the item is enabled.
If there exists a ON_UPDATE_COMMAND_UI handler, en-/disabling the item is determined by the handler (pCmdUI->Enable(bEnableState)).
Also keep in mind that:
You may not call EnableMenuItem() yourself, instead call pCmdUI->Enable(bEnableState) in an ON_UPDATE_COMMAND_UI handler. This affects not only the menu item, but any other "command"-type item (with the same ID), eg main menu, context menu, toolbar or rebar button.
Where to put the handler, is a matter of application design and depends on the data you are processing or representing. It can be put in the mainframe class (if it depends on some "global" data or setting), in the document class (if it depends on or changes some data or setting in the document - possibly affecting all views), or in the view class(-es) (depending on or affecting the current view only).
In your case, if I understand correctly, the item is disabled because the handler is in the CDialogEx-derived class, but no instance of this class has been created yet, ie there exists no ON_COMMAND handler for your ID_EDIT_PROPERTIES command.
Per m_bAutoMenuEnable, When this data member is enabled (which is the default), menu items that do not have ON_UPDATE_COMMAND_UI or ON_COMMAND handlers will be automatically disabled when the user pulls down a menu.
I admit that I don't know ii it is different for CDialogEx, But for CDialog I found that the UPDATE_COMMAND_UI didn't ever work unless I handled the WM_KICKIDLE event.
In your OnKickIdle event handler make a call to:
CWnd::UpdateDialogControls
There is a short tutorial on it here.
Forgive me if CDialogEx supercedes this information and I will remove the answer.
I have a wx.html2 widget in my panel. Sadly wx.html2 doesn't have many event listeners (http://wxpython.org/Phoenix/docs/html/html2.WebView.html#events-events-emitted-by-this-class).
Now I have this binding to my panel (self is the panel);
self.Bind(wx.EVT_KEY_DOWN, self.OnRightClick)
.. and it works when I type in a blanco panel/frame as intended.
I wonder if there is a way to add more event listeners to the wx.html2 manually or make a global event listener that listens, no matter the sub-widget the event happens in.
This does not work either (self.wv is the wx.html object);
self.wv.Bind(wx.EVT_KEY_DOWN, self.OnRightClick)
Update
I'm fixing the catching of keys/mouse-actions with JavaScript inside my HTML page now. It works, but I would like it more that actions can be bound to the wx.html2 object.
There are only a few events emitted by WebView, all of which can be found in WebView - wxPython (Phoenix) 2.9.5.80 documentation.
I need to get the list of all events fired in a Qt Widget ( Qt C++) like an utility which can capture all events or some function which will be called and the event details to be passed to the function every time an event is fired.
Can somebody tell me how to do this or is there any free utility available for this purpose ?
QObject::installEventFilter is what you want. You can see all events coming into an object.
If you need to see all events for everything, you can install event filter on QApplication, see documentation to QCoreApplication::notify:
Installing an event filter on QCoreApplication::instance(). Such an
event filter is able to process all events for all widgets, so it's
just as powerful as reimplementing notify(); furthermore, it's
possible to have more than one application-global event filter. Global
event filters even see mouse events for disabled widgets. Note that
application event filters are only called for objects that live in the
main thread.
If you make a class derived from QWidget (let's call it RecordingWidget) you can reimplement it's event() function to record in whatever manner you'd like (maybe keep a log in a static member of RecordingWidget) and then continue to pass the event to QWidget's default event function:
bool RecordingWidget::event(QEvent *event)
{
// Record stuff
...
// Send the event through QWidget's default event implementation
return QWidget::event(event);
}
How can I catch a click on an item, and then change all it's subitems states?
I know I can get the selected item with GetFirstSelectedItemPosition, but how do I use the SetItemState on the given position?
EDIT: I was basically looking for this: m_ListControl.SetExtendedStyle(LVS_EX_FULLROWSELECT)
Create a notification handler for the LVN_ITEMCHANGED notification. This handler will be called whenever a new item has been selected either using the mouse or the keyboard. If you particularly need to handle mouse clicks, create a notification handler for the NM_CLICK notification instead.
Both event handlers' LPARAM parameter points to a structure that contains a member called iItem. This is the index to the item just selected or clicked. Use this iItem as the first parameter to the SetItemState method.