I am working on an issue where clicking on a wxButton leads to no reaction at all. Experience tells this is normally due to another window overlapping the button. For example the bug is that a wxStaticText was created much too large. You only see the text, which does not overlap the button so you think everything is alright. But clicking on a part of the button that is overlapped, nothing will happen as the click goes to the wxStaticText. Until now we "debugged" these kinds of issues by looking at the code with our eyes.
Is there a better way to debug such an issue? For example a debug mode where you would click somewhere and it would tell you the window under the cursor would be very helpful.
Some ideas:
* You would need to catch all mouse events in one place (I think there is a filter function for this?)
* When receiving a say "left down" event, you would need to find the window you just clicked on. I searched, but did not find any solution on how to do this.
* You would then display the position, size and label of the window. This would normally be enough to understand which other window overlaps your button.
Get the Window under the Cursor. Debug wrong Window overlaps. Topic is solved
Re: Get the Window under the Cursor. Debug wrong Window overlaps.
Hi,
Could you please post some code?
Thank you.
Could you please post some code?
Thank you.
Re: Get the Window under the Cursor. Debug wrong Window overlaps.
Things you need:
wxAppConsole::FilterEvent
https://docs.wxwidgets.org/trunk/classw ... c6f602e20c
wxWindow* wxFindWindowAtPoint
https://docs.wxwidgets.org/trunk/group_ ... f3d3e406f0
However, if you're using sizers, sibling controls normally can't overlap (unless the window is too small to display them). And if you see the button visually getting pressed, the issue is somewhere else and not caused by overlapping windows.
wxAppConsole::FilterEvent
https://docs.wxwidgets.org/trunk/classw ... c6f602e20c
wxWindow* wxFindWindowAtPoint
https://docs.wxwidgets.org/trunk/group_ ... f3d3e406f0
However, if you're using sizers, sibling controls normally can't overlap (unless the window is too small to display them). And if you see the button visually getting pressed, the issue is somewhere else and not caused by overlapping windows.
Use the source, Luke!
Re: Get the Window under the Cursor. Debug wrong Window overlaps.
EXCELLENT! That works as hoped for and will be a good tool in our toolbox for looking at all kind of windows / window properties.
Somehow my google fu broke down and I did not find the function wxFindWindowAtPoint().
We indeed do not use sizers. I hope to get around to it one day, but right now we are simply struggling to create a new version of our software before XMas.
With the information from doublemax (THANK YOU!) it is almost trivial to write such a debug tool but just in case someone is interested in my code:
Somehow my google fu broke down and I did not find the function wxFindWindowAtPoint().
We indeed do not use sizers. I hope to get around to it one day, but right now we are simply struggling to create a new version of our software before XMas.
With the information from doublemax (THANK YOU!) it is almost trivial to write such a debug tool but just in case someone is interested in my code:
Code: Select all
int WX_App::FilterEvent(wxEvent& event) //override
{
if (wxMouseEvent* pMouseEvent = dynamic_cast<wxMouseEvent*>(&event))
{
if (pMouseEvent->ButtonDown(wxMOUSE_BTN_LEFT))
{
wxCoord x = pMouseEvent->GetX();
wxCoord y = pMouseEvent->GetY();
wxString s;
s << x << L", " << y;
wxWindow* pWnd = wxFindWindowAtPointer(wxPoint(x, y));
if (pWnd)
{
wxPoint pt = pWnd->GetScreenPosition();
wxSize size = pWnd->GetSize();
s << ", x,y,w,h == " << pt.x << ", " << pt.y << ", " << size.x << ", " << size.y;
wxString sName = typeid(*pWnd).name();
s << ", typename == " << sName;
// Test for classes we derived from wxWindow like CX_Button
if (CX_Button* pBtn = dynamic_cast<CX_Button*>(pWnd))
{
handle CX_Button here
}
else
{
s << ", pWnd->GetLabel() == " << pWnd->GetLabel();
}
}
else
{
s << L", pWnd == nullptr";
}
Somehow output "s" here. I put it into our StatusBar.
}
}
return -1;
}
Re: Get the Window under the Cursor. Debug wrong Window overlaps.
Hi,
You should start using sizers. Then all those things will disappear.
Thank, you.
You should start using sizers. Then all those things will disappear.
Thank, you.