Search code examples
rgwidgets

Change mouse cursor of a widget in gWidgetsRGtk2


I want to change the mouse cursor to a hand, for clicking an image.

hlp<-gimage("help", dirname="stock", size="dialog")
addHandlerClicked(hlp, handler=function(h,...) {
   browseURL("http://....")})

I have read other post related but setCursor doesn't work on Widgets.

Thank you


Solution

  • Looking here (how can i change the shape mouse cursor in gWidgets RGtk2?) you can see what you need for RGtk2. Try this:

    library(RGtk2)
    w <- gwindow()
    g <- ggroup(cont=w)
    gbutton("button", cont=g)
    img <- gimage("/Users/verzani/bubble-gum-art.jpg", cont=g)
    old_cursor <- getToolkitWidget(img)$getWindow()$getCursor()
    cross <- gdkCursorNew("GDK_TCROSS")
    
    addHandler(img, "enter-notify-event", handler=function(h,...) {
               getToolkitWidget(img)$getWindow()$setCursor(cross)
               TRUE
               })
    
    
    addHandler(img, "leave-notify-event", handler=function(h,...) {
               getToolkitWidget(img)$getWindow()$setCursor(old_cursor)
               TRUE
               })
    

    That works under Mac OS X. If it doesn't work for you, can you indicate which OS you are trying?