问题
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 wishes
Thomas
回答1:
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=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] = "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 comboboxes
items <- state.name
sapply(options[,2], function(i) i[] <- items)
来源:https://stackoverflow.com/questions/12894097/gwidgets-resize-combobox-to-fit-content