0

考虑以下输入框:

w <- gwindow()
g <- ggroup(cont=w, horizontal=F)
ed <- gedit(cont=g)
cbb <- gcombobox(letters, editable=T, use_completion=T, cont=g)

gedit()当/输入框包含字符串时,如何制作gcombobox()红色的背景和白色的前景(文本本身)asdf

4

1 回答 1

0

正如评论中所建议的,以下内容可以完成这项工作,您可以red#FF6666(Light Faded Red) 或任何颜色替换:

addHandlerKeystroke(ed, function(h,...){
    if(svalue(ed)=="asdf"){ 
        ed$widget$modifyBase(GtkStateType["normal"], "red") 
        ed$widget$modifyText(GtkStateType["normal"], "white") 
    } else {
        ed$widget$modifyBase(GtkStateType["normal"], NULL)
        ed$widget$modifyText(GtkStateType["normal"], NULL) 
    }
})

因为gcombobox()它略有不同:

addHandlerChanged(cbb, function(h,...){
    if(svalue(cbb)=="asdf"){ 
        cbb$widget$getChildren()[[1]]$modifyBase(GtkStateType["normal"], "red")
        cbb$widget$getChildren()[[1]]$modifyText(GtkStateType["normal"], "white")
    } else {
        cbb$widget$getChildren()[[1]]$modifyBase(GtkStateType["normal"], NULL)
        #cbb$widget$getChildren()[[1]]$modifyText(GtkStateType["normal"], NULL)
    }
})
于 2014-07-19T17:48:40.413 回答