Vaadin expand ratio for Label with potentially empty value - css

In one of our pages I've created a detail screen with some information divided in blocks. I've used HorizontalLayouts with setExpandRatio for this. Here is how this is divided (all values made black for privacy reasons):
The final Label of the second row (now containing ---) should actually be empty instead. All the blocks are basically Vaadin Labels, with values in it. However, these values can sometimes be null, in which case I don't want to show anything in the Label.
When I use an empty String however instead of ---, it will look like this:
As you can see at the final Label of the second row, it is now missing it's border (and possible other styles we might add in the future), because Vaadin automatically put the expandRatio of Labels with an empty input to 0, turning the width to 0px.
I know you can set the actual width of a Label as filler, but in this case it's simply a question whether the value that's supposed to be in that Label is or isn't null.
I've also tried a space as value, but it just ignores it and behaves the same as the empty value. And when I " " as value (without setting the Label to HTML-mode), it outputs this literally as on the screen.
Is there any value I could use for the Label when the value is null to still show the style with borders, but without value?
EDIT: Hmm, when I use and set the ContentMode of the Label to HTML it seems to work. Is this the intended work-around for this issue (which means I'll have to set ContentMode to HTML for all Labels with the potential of containing an empty value), or is there another workaround by changing this 'empty' value alone?

Ok, I ended up using my solution provided in the EDIT. For all these Labels I had already created a BorderedLabel class, so I simply added setContentMode(ContentMode.HTML); to it, and used when the value is null in our util helper class.

Related

anno_text function in Complex Heatmap, how to name row annotation in the top?

I am struggling to modify a row annotation label from the bottom to the top of the column.
The function anno_text has the parameter show_name = FALSE. However, it does not have the parameter side (or name_side). As a consequence, the annotation label is always put at the bottom of the column.
Would anyone know how to change that? I want to annotate at the top instead.
You can use grid.text to add annotations anywhere rather than show_name = TRUE in anno_text() directly, follow the guide 6.2.2 Add titles for row annotations.

PHPExcel: how to get cell's fill color, that is set using conditional formatting?

I have a cell that has conditional formatting applied and a static color (green). The cell is red, if you view it in Excel (because of conditional formatting). If I use getStartColor(), I get the static color: green. If I use getEndColor() I get white. I'd like to get the red one.
How can I do that?
$conditionalStyles = $objPHPExcel->getActiveSheet()
->getStyle('B2')
->getConditionalStyles();
will return the conditional styles for the specified cell as an array:
You can loop through those, using getConditionType(), getOperatorType() and getConditions() (which can return an array of conditions) , etc to identify the conditional rule, test if the cell value matches that rule, and then use getStyle() to retrieve the style details

Sort vertical headers of QTableWidget

I have a QTableWidget that is used to display lots of data, basically derived from a function f(a,b). All a values go into the horizontal header, all b values into the vertical header and all f(a,b) into the corresponding cell.
The columns should be sortable. When a user clicks a column, all values in that column are sorted and all other columns are also "synchronized", since whole rows are sorted (using the clicked column as a sort criterium).
This works. Except for the "header column", the vertical header. The vertical header does not change, it does not synchronize with the reorganized rows. Is this the intended behaviour? Is it a bug in my code? How do I make the vertical header sort, too? Or do I need to add my b's to an ordinary column?
edit: I solved it now by making the header column an ordinary column. Though, I would still be interested in why the vertical header does not sort with the other columns.
Try to use QTableView instead of QTableWidget.
And use QAbstractTableModel for computing f(a,b)

QTableWidgetItem multiple lines disappearing

I use a subclassed QTableWidget with QTableWidgetItems in cells to display certain data. In the first row, I have a set of numbers separated by new lines in each cell. My problem is that when I increase font size/decrease cell size, some lines completely disappear, allthough the cell is definitely high enough to contain them.
This usually appears when there is a 2-digit number with some other lines under it and (probably) the font size is greater than the box width can match. I have the elide mode set to none to suppress the "three dots" that appear when this happens.
this->setTextElideMode(Qt::ElideNone);
The first row is resized by
this->resizeRowToContents(0);
this->setRowWidth(0, this->rowWidth(0) + 10);
so that its high enough.
However, the numbers keep on disappearing. Example shown here, note the font size change and missing numbers.
http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug1.png
http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug2.png
I'm starting to be quite desparate about this...any help highly appreciated.
Just to investigate the problem, try:
Make shure that string is correctly created (2,5,10,3) and not (10,3)
Try letters instead of numbers to make shure that they are shown
Try use 3digits nuber alongside with 2digits and see what is happened
May be workaround this by using 01,02 numbers?
Try resizeColumnsToContents() instead of setColumnWidth. If that doesn't work, try calling resizeColumnsToContents() before resizeRowToContents(0).
By the way, is there any reason for calling resizeRowToContents(0) instead of resizeRowsToContents() (note the different name)?

How to make sure columns in QTableView are resized to the maximum

I'm not sure how to ask this, so, feel free to ask for more information.
It seems that tableView->resizeColumnsToContents() will only resize all the columns based on data in current view. Which means that if I have more data below (which is longer in terms of counts of words), those words will be wrapped down (if the wordWrap property is set to true).
The weird thing is, if I scroll down to the bottom and refresh the data, tableView will resize those columns correctly. It seems as if tableView didn't know there are longer text below.
So, my question is, how can I make sure those columns are resized to the max based on all of the data?
My codes
QSqlTableModel *model = new QSqlTableModel;
model->setTable("item");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
tableResult->setModel(model);
tableResult->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableResult->setSelectionBehavior(QAbstractItemView::SelectRows);
tableResult->setSelectionMode(QAbstractItemView::SingleSelection);
tableResult->resizeColumnsToContents();
tableResult->resizeRowsToContents();
Update 1
I've tried tableResult->scrollToBottom() and it will only resize based on items at the bottom. So, if there are longer words in the middle, those words will get wrapped.
Update 2
If anyone would like to understand what I'm talking about, just download this example. You'll see that clicking the PushButton will generate a data that's not resized correctly.
Update 3
Possibly a bug: https://bugreports.qt.io/browse/QTBUG-9352
I managed to find a workaround for this issue, you just need to hide the table before calling resizeColumnsToContents().
For an example:
tableResult->setVisible(false);
tableResult->resizeColumnsToContents();
tableResult->setVisible(true);
I think that is because QSqlTableModel loads data on demand and the view calculates the column widths based only on data that is available. If you don't need your columns to be user-resizable, you can try this:
tableResult->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
I used the same workaround as described by amree, which worked great for the column widths, but tableView->resizeRowsToContents() wasn't working correctly if any offscreen columns had multiline cells that should have caused a row's height to increase.
I looked into the Qt source and it appears that some of the calculations depend on the viewport geometry. This seems to make everything work correctly for both columns and rows:
#include <limits>
tableView->setVisible(false);
QRect vporig = tableView->viewport()->geometry();
QRect vpnew = vporig;
vpnew.setWidth(std::numeric_limits<int>::max());
tableView->viewport()->setGeometry(vpnew);
tableView->resizeColumnsToContents();
tableView->resizeRowsToContents();
tableView->viewport()->setGeometry(vporig);
tableView.setVisible(true);

Resources