标签在小部件中的位置 [英] position of the labels in a widget

查看:82
本文介绍了标签在小部件中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的小部件中,可以更改无线电"组标签的位置.我想要这样的东西,而不是在项目上方输入"Type":

In the widget below, is it possible to change the position of the label of the "radio" groups. I would like something like that instead of having "Type" above the items:

Type        o Quantitative
            o Qualitative

win <- gwindow("Empirical Phase Diagram")

BigDataGroup <- ggroup(cont=win)
DataGroup <- gframe("Data", container = BigDataGroup, horizontal=FALSE)

grp.file <- ggroup(horizontal=FALSE, container = DataGroup)
lbl.file <- glabel("File: ", container = grp.file)
browse.file <- gfilebrowse(container = grp.file)

Input1Group <-  gframe("First input variable ", container = DataGroup, horizontal=FALSE)
grp.text.input1 <- ggroup(horizontal=FALSE, container = Input1Group)
lbl.text.input1 <- glabel("Column index",  container = grp.text.input1)
insert.text.input1 <- gedit(text="A", container = grp.text.input1)
grp.type.input1 <- ggroup(horizontal=FALSE, container = Input1Group)
#addSpring(grp.type.input1)
lbl.type.input1 <- glabel("Type ", container = grp.type.input1)
insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), container = grp.type.input1) 

Input2Group <-  gframe("Second input variable ", container = DataGroup, horizontal=FALSE)
grp.text.input2 <- ggroup(horizontal=FALSE, container = Input2Group)
lbl.text.input2 <- glabel("Column index", container = grp.text.input2)
insert.text.input2 <- gedit(text="B", container = grp.text.input2)
grp.type.input2 <- ggroup(horizontal=FALSE, container = Input2Group)
lbl.type.input2 <- glabel("Type ", container = grp.type.input2)
insert.type.input2 <- gradio(items=c("Quantitative", "Qualitative"), container = grp.type.input2) 

grp.text.output <- ggroup(horizontal=FALSE, container = DataGroup)
lbl.text.output <- glabel("Output variable range ", container = grp.text.output)
insert.text.output <- gedit(initial.msg="type a range e.g. C:AD", container = grp.text.output)

OptionsGroup <- ggroup(horizontal=FALSE, container = BigDataGroup)
grp.colorspace <- ggroup(horizontal=FALSE, container = OptionsGroup)
insert.colorspace <- gradio(items=c("RGB", "LAB", "LUV"))
lbl.colorspace <- gframe("Color space ", container = grp.colorspace)
add(lbl.colorspace, insert.colorspace)

GoGroup <- ggroup(horizontal=FALSE, container = BigDataGroup)
addSpring(GoGroup)
read <- gbutton(text="Go", container = GoGroup, 
    handler = function(h, ...) {
    print(EPD(filename=svalue(browse.file), 
        input1=svalue(insert.text.input1),
        input2=svalue(insert.text.input2),
        outputs=svalue(insert.text.output),
        color.space=svalue(insert.colorspace))
        )
    }
)

推荐答案

两件事:

gWidgets中,您可以使用glayout容器在左侧放置标签.像这样:

In gWidgets you can use a glayout container to put labels on the left. Something like:

tbl <- glayout(cont=parent_container)
tbl[1,1] <- "Type" ## or  glabel("Type ", container = tbl)
tbl[1,2] <- (insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), container = tbl))

后一个双重分配使您可以访问单选窗口小部件.您也可以使用tbl [1,2]来获得它.效果很好,但是您需要对行索引进行一些记账.

The latter double assignment gives you access to the radio widget. You can also get this with tbl[1,2]. This works fine, but you need to do some bookkeeping for the row index.

gWidgets2(现在仅在github上)中,还有gformlayout容器使此操作更容易:

In gWidgets2 (on github only right now) there is also the gformlayout container which makes this easier:

flyt <- gformlayout(cont=parent_container)
insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), 
  horizontal=FALSE,
  label = "Type", container = flyt)

顺便说一句,如果您使用的是gWidgets2RGtk2,则可以修改此标签的字体,但它超级hacky.例如:

As an aside, if you are using gWidgets2RGtk2 you can modify the font of this label, but it is super hacky. E.g.:

get_labels <- function(fl) {
  children <- Map(function(x) x$getWidget(), fl$widget$getChildren())
  labels <- Filter(function(x) is(x, "GtkLabel"), children)
  names(labels) <- sapply(labels, function(x) x$getText())
  labels
}

## Then to set the font of a label you can do:
labels <- get_labels(flyt)  
flyt$set_rgtk2_font(labels[["Type"]], list(weight="bold"))

而且,如果您仍在使用tcltk,则此功能应该可以工作:

And, if you are still using tcltk, this function should work:

set_formlayout_font <- function(fl, value, row) {
  l = tcl("grid", "slaves", fl$widget, row=row-1, column=0)
  fl$set_font_ttk(value, l)
}
set_formlayout_font(fl, list(color="blue"), 2) ## 2nd row

这篇关于标签在小部件中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆