本文介绍了gWidgets:调整组合框以适应内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用gWidgets和RGtk2创建了一个GUI。 GUI的一部分是带有一组gcombobox的glayout。 在使用Gtk +运行X11的Mac上,组合框的宽度被调整大小以适应文档中最长的文本字符串组合框。在Windows中,这种情况不会发生,组合框将获得滚动条以容纳长文本字符串(请参阅图片)。 我试过关闭能见度并强制重绘,但大小保持不变。 $ b 是否有强制改变Windows机器的大小? 持有相关小部件的容器代码如下: optionsBox< - ggroup(cont = controlGroup) addSpring(optionsBox) options< - glayout(cont = optionsBox,spacing = 5,fill ='y') optList< - list() options [1,1,anchor = c(1,0)]< - 'Category:' options [1,2,anchor = c(-1,0)]< - optList $ category< - gcombobox(category,cont = options) options [2,1,anchor = c 1,0)]< - 'Order:' options [2,2,anchor = c(-1,0)]< - optList $ order< - gcombobox(order,cont = options) options [2,3,anchor = c(1,0)]< - optList $ numeric< - gcheckbox('numeric',checked = TRUE) options [3,1,anchor = c(1,0)] options [3,2,anchor = c(-1,0)]< - optList $ plottype< - gcombobox(c('Bar','Line'),cont = options) addSpring(optionsBox) 祝愿 Thomas 解决方案我无法在Windows上轻松测试,但有几件事情应该会有帮助。首先,确保 glayout 对象的父容器不限制初始大小。 (在下面的示例中,尝试设置 do_expand = FALSE 以查看会发生什么情况。)除非您使用大小设置窗口小部件的大小方法(不是最好的用法,但有时你可以做的所有)初始大小将来自满足小部件的大小要求。 library(gWidgets) options(guiToolkit =RGtk2)w g do_expand = TRUE options< - glayout(cont = g,spacing = 5,expand = do_expand) items< - options [1,1] =vanilla options [1,2]< - gcombobox(items,cont = options) options [2,1] =expand options [2,2,expand = TRUE]< - gcombobox(items,cont = options) options [3,1] =填充 options [3,2,expand = TRUE,fill =y]< - gcombobox(items,cont = options) options [4,1] = size options [4,2] size(cb) ##填充组合框项< - state.name sapply(options [,2],function(i)i []< - items) I have created a GUI using gWidgets and RGtk2. A part of the GUI is a glayout with a set of gcomboboxes. These boxes are initially empty and gets populated once a file is imported.On mac with Gtk+ running through X11 the width of the comboboxes gets resized to fit the longest textstring in the combobox. On windows this doesn't happen and the comboboxes gets scrollbars to accomodate the long text strings (see pictures).I have tried turning visibility off and on to force a redraw but the size stay fixed.Is there anyway to force the resizing on windows machines?The code for the container holding the relevant widgets are:optionsBox <- ggroup(cont=controlGroup)addSpring(optionsBox)options <- glayout(cont=optionsBox, spacing=5, fill='y')optList <- list()options[1, 1, anchor=c(1,0)] <- 'Category:'options[1, 2, anchor=c(-1,0)] <- optList$category <- gcombobox(category, cont=options)options[2, 1, anchor=c(1,0)] <- 'Order:'options[2, 2, anchor=c(-1,0)] <- optList$order <- gcombobox(order, cont=options)options[2, 3, anchor=c(1,0)] <- optList$numeric <- gcheckbox('numeric', checked=TRUE)options[3, 1, anchor=c(1,0)] <- 'Plottype:'options[3, 2, anchor=c(-1,0)] <- optList$plottype <- gcombobox(c('Bar', 'Line'), cont=options)addSpring(optionsBox)best wishesThomas 解决方案 I can't test this easily on windows, but a few things should help out. First, make sure the parent container for the glayout object isn't constraining the initial size. (In the example below try setting do_expand=FALSE to see what happens.) Unless you set the size of the widget with the size<- method (not the best usage, but sometimes all you can do) the initial size will come from satisfying the size requests of your widgets. library(gWidgets)options(guiToolkit="RGtk2")w <- gwindow()g <- ggroup(cont=w)do_expand=TRUEoptions <- glayout(cont=g, spacing=5, expand=do_expand)items <- ""options[1,1] = "vanilla"options[1,2] <- gcombobox(items, cont=options)options[2,1] = "expand"options[2,2, expand=TRUE] <- gcombobox(items, cont=options)options[3,1] = "expand, fill"options[3,2, expand=TRUE, fill="y"] <- gcombobox(items, cont=options)options[4,1] = "size"options[4,2] <- (cb <- gcombobox(items, cont=options))size(cb) <- c(250, -1)## populate comboboxesitems <- state.namesapply(options[,2], function(i) i[] <- items) 这篇关于gWidgets:调整组合框以适应内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 01:07