GWT: Flextable having fixed column size - css

I need a FlexTable in GWT where I can add items at run time. The FlexTable is inside a ScrollPanel, so that when horizontal content exceeds display area a scroll bar appears.
The problem is when there are 2-3 columns they are spaced widely but as column count increases, the cell takes the minimum required area of 100px.
I need to ensure that Cell always takes 100px only. I have been doing following but no success.
myflextable.getCellFormatter().setWidth(0, col, "100px");

Please try with getFlexCellFormatter().setWidth() method.
Please check also that have you given flextable width to 100%.

The problem may be that the flextable is set to be too wide initially. It will fill the scrollpanel by default, and then as a result the columns will stretch to their maximum width.
You should set the width of the flextable explicitly in the beginning, and it will automatically resize correctly when more columns are added at run time.
Here is an example for when you have initially one row and two 100px columns:
ft = new FlexTable();
ft.addStyleName("flextable");
ft.setWidth("200px");
for (int x = 0; x < 2; x++) {
ft.setText(x, 0, "cell");
ft.getCellFormatter().addStyleName(x, 0, "testcell");
}
scrollpanel.add(ft);
and your css should say this:
.flextable {
table-layout: fixed;
}
.testcell {
width : 100px;
}
Note that the flextable is initially set to 200px width, as we start with two columns.
In the CSS file, the table-layout attribute must be set otherwise the columns will get smaller than 100px as you add more (until the cells reach their minimum width, defined by their content).
Also, remember to add the stylename "testcell" to any new cells that you add at runtime.

Related

Set minimum row-height of QComboBox

I am trying to set the minimum height of the rows in the QComboBox dropdown menu without changing their width or the size of the QComboBox itself.
By default the width and height of the row items are calculated by its data. To make the dropdown list resize to the width of the data I am calling
view()->setMinimumWidth(view()->sizeHintForColumn(0);
in the combobox's ::showPopup().
However, since I have different font sizes in rows, I would like to enforce a minimum height on each row.
I tried to use setSizeHint on each QStandardItem that is added in the first column to the rows but without success. I tried:
item->setSizeHint(QSize(item->sizeHint().width(), minHeight));
(https://stackoverflow.com/a/10749345/1981832)
But this lead to the dropdown menu not resizing to the data's width.
So, I tried to leave the width "unset". However, both
item->setSizeHint(QSize(QSize().width(), minHeight));
and
item->setSizeHint(QSize(0, minHeight));
did not work. Does anyone have an idea how I can enforce a minimum height on the rows of the QComboBox without messing up the automatic width calculation?
Just use this lines:
QComboBox combo;
QListView *view = new QListView(&combo);
view->setStyleSheet("QListView::item{height: 100px}");
combo.setView(view);
Or write this code in qss file:
QListView::item {
height: 30px;
}
After that use:
QComboBox::setView(QAbstractItemView *itemView)

Accessing layout data from itemrenderer

I am working on a FLEX / AIR Spark list which lists a collection of images with differing width and height.
I am using a custom layout which works this way:
decide how many images can be fit in the current row based on their widths.
justify them in such a way that first image in the row obeys the "left" margin and the last image in the row obeys "right" margin, so with the "top" and "bottom" as specified by the user, let us say 10 pixels.
As an example, assuming that the current row has 4 images, the images 1 & 4 will have 10 pixels each as "left" margin "right" margin respectively. But the left and right gaps between 1-2, 2-3 & 3-4 will be equally divided based on the varying widths.
now i would like to draw a background that will fill the dynamic area. Please see the image below to get an idea:
Layout requirement Image
** In the image, The grey area is the background I would like to draw, and the colored rectangles represent images of differing widths and heights.**
the "rowHeight" is variable based on the maximum height of individual images within the row.
Issues:
a) Now I would like to draw a background (see the grey area in the pic) that fills the background area of the list. I know the current item's width & height, but I don't know the rowHeight decided by the layout, left and right margins between the images.
Something like:
bgRect:Rectangle = new rectangle ( 0, 0, (imgWidth + (LeftMargin/2) + (Right Margin/2) ), rowHeight)
b) How / where should the background be implemented? if i add the BG area within the item renderer based on the layout, again the layout will be relaid.
Children should be added in the createChildren method. Drawing (painting) the background should happen in updateDisplayList method.
You can pass data to your itemrenderers via an itemrenderer factory. See - Flex - Sending a parameter to a custom ItemRenderer?.
var productRenderer:ClassFactory = new ClassFactory(ProductRenderer);
productRenderer.properties = { showProductImage: true };
myList.itemRenderer = productRenderer;

Dojo GridX with 100% width and adaptable column widths? [duplicate]

According to documentation:
https://github.com/oria/gridx/wiki/Create-the-Simplest-Gridx
Never forget to call grid.startup(), since the column width
calculation and layout rendering need to access the geometry
information of grid DOM nodes.
If I have the grid with columns, that have no width specified, and autoWidth is set to false, startup() calculates the size of columns so, that they fill the whole viewport horizontally. However, if viewport is expanded, and extra empty space is inserted after the last column. If the viewport is narrowed, the last columns are not more visible (and no scroll is rendered).
So I think the best workaround is to launch the recalculation of columns sizes manually, after the viewport was resized. But I can't find an API method to do that.
How to call column width recalculation and layout rendering on existing grid?
What I've done for this situation is setup an event handler to watch for window resize events, then set the width to the current grid width. When creating the grid:
function _resizeToWindow(grid, gridId) {
grid.resize({w: dom.byId(gridId).offsetWidth, h: undefined});
}
on(window, "resize", function() {
_resizeToWindow(grid, gridId);
});
It looks a little odd to resize the grid to the current width of the grid, but calling that function will cause the grid to be rendered again with appropriate column widths for the new grid width.

Relative re-sizing of QTableWidget's columns

I am using a QTableWidget with 4-5 columns in a dialog. The dialog is resizable, I want table widget columns to resize according to dialog size i.e. if I increase dialog width, columns which are initially set with large width should expand more than the columns which were set with less width.
In short, I want relative resizing like column1 should occupy 20%, column2 occupy 50% of my table width (which increases with dialog width) and so on.
How this can be achieved for QTableWidget in Qt ?
Any solution, pointers or hints would be very helpful.
It should just be a matter of updating the column widths whenever your dialog resizes.
MyDialog::resizeEvent(QResizeEvent *event) {
int width = ui->tableWidget->size().width();
ui->tableWidget->setColumnWidth(0, width * .2);
ui->tableWidget->setColumnWidth(1, width * .5);
...
}
You could also subclass QTableWidget directly and do this same thing.

Can I make Grid Layout stretch like an HTML table does?

I have use the mx:Grid layout component to layout some form elements in a manner very similar to an HTML table. However, the result does not stretch out horizontally when you resize the app like an HTML table would. How can I make it do that?
Try setting the width and height of the Grid element to a percentage value.
I'm using a Grid on one of my main applications, and I've set the width/height to 100% and it resizes just fine.
You'll likely need to set the width and height of the rows and items (GridRow and GridItem) as well, depending on how you want the rows/columns to resize.
Edit if you're creating the Grid programmatically (e.g. in a .as file), you'll need to set these values as percentages as follows:
var grid:Grid = new Grid();
grid.percentWidth = 100;
grid.percentHeight = 100;

Resources