Sort vertical headers of QTableWidget - qt

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)

Related

Vaadin Grid Column Re-Order (Vaadin 14 / Flow)

I'm using Vaadin grid and have two grids which are more or less configured the same. One has a header row configured. I retrieve it by prependHeaderRow() method.
On both of the grids I enable column reordering by setting setColumnReorderingAllowed(true).
On both I'm then able to drag columns. BUT the one without header row lets me reorder the columns (see fig 1) and the other one prevents me from reordering by indicating all columns in grey-ish while dragging the column (fig 2).
Figure 1
Figure 2
Has somebody any idea why Vaadin grid is preventing my from re-ordering while header row is prepended? And if yes how I can get around it?
Kind regards
Ben

Set CONSTRAINED_RESIZE_POLICY for columns without first (for number of row) in tableView JavaFx

I have tableView with first column for row number. I would like to set CONSTRAINED_RESIZE_POLICY for all columns without first.
I made:
//First column implementation
column.setPrefWidth(40);
column.setResizable(false);
... //Make other columns
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
So I have first column with width I chose but other are wider than without last line in code above but still there is one additional void column.
And I have another question because I looked for resizing column to length of the longest text in column (I need it for first column) but I only found old answers with very long and tricky solutions. Is there any simple solution (method) to do it?
Edit: I found that when I try to manually resize columns, that they resize properly (as they should with CONSTRAINED) after only click to resize one of columns so I have a question, why they didn't resize from the start like I described above but after trying to manual resize. I think that problem is with setResizable false on first column but how can I repair this?
I found solution. To make other columns CONSTRAINED_RESIZE_POLICY there must be set size of the first column like below:
column.setMinWidth(40);
column.setMaxWidth(40);
and it's working without line setResizable(false).

Flex 3 prevent duplicate stacking in ColumnChart control

Here is my Problem:
I'm currently using a ColumnChart to display 6 label/value pairs.
When two labels are the same, the chart stacks them up, one on top of the other.
I want to display these duplicates side by side, their value might be the same or it might be distinct.
My first thought was to append a unique id to the label, but that's not possible according to the client. So, is there a way to tell the chart to also take a hidden id into consideration?
Someone suggested to do some sort of grouping, but I need to display each chart separate, as if they were distinct charts.
the chart's data provider is an array of these objects:
obj.description = "des";
obj.countV = 3;//some arbitrary number
obj.id = 2; //a unique id...
the chart code:
I found my solution:
append an index # at the end of each column label.
Use a labelFunction to remove the last char:
columnLabel.slice(0, -1);
that fooled the chart into thinking they're all uniques but display all duplicates side by side.

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);

Flex: Make columns aligned between 2 DataGrids?

I have 2 advanced data grids, one above the other. They both have the exact number of columns, and pertain to each other in the same way. But each is showing different data, which is why I split into 2 grids. However, on each one you can resize the columns, what I would like is to make it so that if you resize a column on either datagrid the same column on the opposite datagrid resizes as well, so they are both always lined up.
Is there a way to do this?
Thanks!!
private function onColumnStretch(e:AdvancedDataGridEvent):void
{
(adg1.columns[e.columnIndex] as AdvancedDataGridColumn).width = (adg2.columns[e.columnIndex] as AdvancedDataGridColumn).width;
}
Add to dategrid:
columnStretch="onColumnStretch(event)"

Resources