QSplitter: How to make second column smaller? - c++

In QtCreator I created a QSplitter which separates vertically a QTreeWidget from a vertical layout with many things on the right.
I would like that this second column by default takes the minimum space it needs to maximise the first one.
I tried setting sizes and vertical policy of the splitter as expanding but surely I'm not doing it right. How can I set this exactly?

You can set this in code with QSplitter::setStretchFactor(int index, int stretch).
You would set the first column to have a stretch of 1 and the second 0.
splitter->setStretchFactor(0, 1);
splitter->setStretchFactor(1, 0);

Related

QTableView, strech all section but the last one resize to content

My table consists of 2 columns: the 1st one stores some strings, the other contains a checkbox only. To make my table a little bit fancy I want to stretch the whole table to the width of its view.
Using
setStretchLastSection(true);
solves the 1st problem. The table looks better, but... OK... the last column is a bit large.
Also I can use
setSectionResizeMode(QHeaderView::Stretch);
The table looks great, but... It isn't my desire. The 1st column should be optimally at least 90% of view's width and the 2nd one small since it contains one checkbox only. Additionally the table shoub be stretched to the view's width. Any Ideas?
Here is a picture just to make my question more understandable)
Here is the solution:
Disable the stretch option for the last column
setStretchLastSection(false);
Set a fixed width for the last column
setColumnWidth(1, fixedWidth)
Stretch the first column
setSectionResizeMode(0, QHeaderView::Stretch)
a bit fancy look

GTK fill last element of FlowBox to end

I am having a (vertical) GTK FlowBox that has multiple children. All but the last are having no fixed size and are just filling the space their child control needs. The last element is in a GtkScrolledWindow and supposed to fill the remainder of the GtkFlowBox. I have tried several layout options but none of them makes the last child fill the remainder of the GtkFlowBox.
The things I have tried:
Setting vertical alignment to Fill for the GtkFlowBoxChild, the GtkScrolledWindow and its child GtkTreeView
Setting the Expand Vertical to TRUEfor all the controls mentioned above
Is it possible to have an element of the GtkFlowBox fill the remainder of the box?
I am using GTK version 3.22.30
My solution was to use a regular GtkBox instead of a GtkFlowBox and make all but the last elements vertically aligned to the start.

In a QFormLayout with labels with enabled word-wrap, layout gets borked one out of 4 times

I have a QFormLayout. The labels on the left vary wildly in length depending on the active language. To work around this, I enabled word wrap on each of the labels. Most of the time this works fine, but sometimes I get strange artifacts:
What is going on with "Option de intermedio"? Why did it decide to break that one, but not the one above? Why is the text cut off, when it's clearly fine in the row two rows down ("Remover ...")?
Most importantly, what can I do about it?
The problem is that the minimum size is not correctly calculated for QLabels with word wrap enabled. You should override minimumSizeHint() and calculate the height of the text manually using QFontMetrics
by the way, you will need to use the version of QFontMetrics that takes also flags and pass it Qt::TextWordWrap
http://doc.qt.io/qt-4.8/qfontmetrics.html#boundingRect-6

How to set minimum width for the first column of the QFormLayout?

How to set minimum width for the first column of the QFormLayout? I can do it for QGridLayout by using QGridLayout::setColumnMinimumWidth(int, int), but cannot find a method to do that for QFormLayout.
It's pretty simple to do. Just set a minimum width on any of the widgets that you've inserted into the first column.
How to set minimum width for the first column of the QFormLayout?
You cannot (off-hand). It was not designed for that as this sounds more like a QGridLayout feature. You could either refactor your design to use QGridLayout, or you could potentially set the size for the rows as you wish, but you would execute that on the row content rather than the layout itself.

How to resize width of columns to data and stretch the last section together in Qt TableView

Anyone knows how to fit the column width to the data in a TableView and then stretch the final column to the size remaining on the widget?
I've tried:
_ui->tableView->resizeColumnsToContents();
_ui->tableView->horizontalHeader()->setStretchLastSection(true);
But only the resizeColumnToContent() work. The last section is unstretched.
Is it even possible without having to dynamically calculate the width manually?
Nethermind. For prosperity here's the solution:
_ui->tableView->resizeColumnsToContents();
_ui->tableView->horizontalHeader()->setSectionResizeMode( 3, QHeaderView::Stretch );
In this case the last column is 3.