[wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

[wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column

Post by Rudra » Sat Oct 10, 2020 7:05 am

Hi,

In my wx application, I show a wxDataViewListCtrl in which I have a bitmap column along with Text columns. The bimap size is 20x20 but I have set row height to 60 due to showing multiline text. I want to show the hand cursor when mouse is above the bitmap only.

I added wxEVT_MOTION for the list and on getting call, finding the column using HitTest and updating the cursor (wxSetCursor()). It udpates the cursor while mourse is over bitmap column.

I am unable to refine more to update cursor only when mouse is over the bitmap. Please suggest.

Thanks
R

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column

Post by doublemax » Sat Oct 10, 2020 7:35 am

Use wxDataViewCtrl::GetItemRect to get the rect for the cell. If the bitmap is always 20x20 and centered, you can calculate its exact coordinates and check if the mouse cursor is inside.
Use the source, Luke!

Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column

Post by Rudra » Sat Oct 10, 2020 9:44 am

doublemax wrote:
Sat Oct 10, 2020 7:35 am
Use wxDataViewCtrl::GetItemRect to get the rect for the cell. If the bitmap is always 20x20 and centered, you can calculate its exact coordinates and check if the mouse cursor is inside.
Thanks for the reply.
yes, it works. I noticed one thing that if tooltip is also being shown for the bitmap then it doesn't let update the cursor. Updating cursor either before or after the GetMainWindow()->SetToolTip(tooltip) doesn't matter. Not sure why.

In case if anyone need the code

Code: Select all


// Bitmap or Cell rect's center
wxRect cell_rect = my_list->GetItemRect(item, column);
int center_x = cell_rect.GetX() + cell_rect.GetWidth()/2;
int center_y = cell_rect.GetY() + cell_rect.GetHeight()/2;

// Bitmap top left
wxPoint top_left(center_x - m_bmp.GetSize().GetWidth()/2,  center_y - m_bmp.GetSize().GetHeight()/2);
				 
// Bitmap right bottom
wxPoint bottom_right(center_x + m_bmp.GetSize().GetWidth()/2, center_y + m_bmp.GetSize().GetHeight()/2);

// Bitmap Rect					 
wxRect bitmap_rect(top_left, bottom_right);

// Update cursor 
if(bitmap_rect.Contains(event.GetPosition()))
	wxSetCursor(wxCursor(wxCURSOR_HAND));
else
	wxSetCursor(wxCursor(wxCURSOR_ARROW));
Thanks
R

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4541
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: [wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column

Post by ONEEYEMAN » Sun Oct 11, 2020 4:41 am

Hi,
What platform?
It may not be possible, because tooltip might change the cursor position. and showing it has preference (from the native platform perspective).

Thank you.

Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.3] Showing hand cursor only above bitmap of wxDataViewListCtrl's bitmap column

Post by Rudra » Wed Oct 14, 2020 8:19 am

ONEEYEMAN wrote:
Sun Oct 11, 2020 4:41 am
What platform?
On windows 10
ONEEYEMAN wrote:
Sun Oct 11, 2020 4:41 am
It may not be possible, because tooltip might change the cursor position. and showing it has preference (from the native platform perspective).
It could be possible. I checked mouse over in explorer. When it shows tooltip it shows the arrow cursor and when it shows the hand cursor e.g in "Quick access" it doesn't show the tooltip.

May be there is some trick to do as I see some Window's applications can show tooltip with arrow cursor

Thank you.

Post Reply