Change mouse cursor of a widget in gWidgetsRGtk2

2019-09-12 23:42发布

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

标签: r gwidgets
1条回答
我只想做你的唯一
2楼-- · 2019-09-13 00:15

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?

查看更多
登录 后发表回答