I have a QT-UI with some labels. It's structured as follows:
All the labels are in a listwidget, this is vertically scrollable . Before i put a large text to the labels, I set its maximumWidth. When I set the large text to the labels, the QLabel inserts a blank line on the top. I'm crazy with it! What can I do to get rid of this empty line?
Here's a photo of the basic UI:
How you can see, I put a green border to some labels, so you can better see the blank line (inserted by QLabel!). I'm just putting text like "visuelle Kontrolle", but QLabel inserts a line break to the begin of my text. So it looks how you can see.
EDIT: Additionally I put a little piece of code, so you can see what I'm doing here. First I set the maximumSize for the labels:
auto width = listCtrl->verticalScrollBar()->sizeHint().width();
auto items = {
ui->m_editKKS,
ui->m_editOrt,
ui->m_editKurzbezeichnung,
ui->m_editLetzterSchaden};
for (QLabel* item : items)
{
auto margin = 15;
item->setMaximumWidth(item->width() - (width + margin));
// item->setStyleSheet("border:1px solid green;");
}
ui->m_editTaetigkeit->setMaximumWidth(ui->m_editTaetigkeit->width() - width);
Then I put a text, to the controls. For each control I'm using setText:
ui->m_editLetzterSchaden->setText("some text comes here...");
and so on...
EDIT:
I noticed something (probably) quite important. If I build my UI so that it is not embraced by a vertical layout, then the QLabels will be displayed correctly. But if I build them up so that all elements are spanned by a vertical layout, then there is the rendering problem (as described above). This extremely strange behavior is comprehensible and man can be switched back and forth: with QVBoxLayout-> display error, without QVBoxLayout-> no errors, and so on ...
Here you can see the UI-Code without vertical layout around the UI-elements:
[?xml version="1.0" encoding="UTF-8"?]
[ui version="4.0"]
[class]PrjNameMeldung1_5[/class]
[widget class="QMainWindow" name="PrjNameMeldung1_5"]
[property name="geometry"]
[rect]
[x]0[/x]
[y]0[/y]
[width]375[/width]
[height]444[/height]
[/rect]
[/property]
[property name="windowTitle"]
[string]MainWindow[/string]
[/property]
[widget class="QWidget" name="centralwidget"]
[widget class="QWidget" name="gridLayoutWidget"]
[property name="geometry"]
[rect]
[x]9[/x]
[y]25[/y]
[width]361[/width]
[height]401[/height]
[/rect]
[/property]
[layout class="QGridLayout" name="gridLayout"]
[item row="3" column="0"]
[widget class="PrjListControl" name="listWidget"]
[property name="sizePolicy"]
[sizepolicy hsizetype="Expanding" vsizetype="Expanding"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[/widget]
[/item]
[item row="1" column="0"]
[widget class="QLabel" name="m_editTPAggregat"]
[property name="text"]
[string]TPAggregat[/string]
[/property]
[/widget]
[/item]
[item row="2" column="0"]
[widget class="QLabel" name="m_labelAuswahl"]
[property name="text"]
[string]Baugruppe[/string]
[/property]
[property name="alignment"]
[set]Qt::AlignCenter[/set]
[/property]
[/widget]
[/item]
[item row="0" column="0"]
[widget class="QLabel" name="m_editTP"]
[property name="text"]
[string]TP[/string]
[/property]
[property name="alignment"]
[set]Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop[/set]
[/property]
[/widget]
[/item]
[/layout]
[/widget]
[widget class="PrjToolBar" name="m_groupMenuBar" native="true"]
[property name="geometry"]
[rect]
[x]9[/x]
[y]425[/y]
[width]357[/width]
[height]16[/height]
[/rect]
[/property]
[property name="sizePolicy"]
[sizepolicy hsizetype="Preferred" vsizetype="Fixed"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[property name="minimumSize"]
[size]
[width]0[/width]
[height]10[/height]
[/size]
[/property]
[/widget]
[widget class="PrjNavigationBar" name="m_groupWindowTitle" native="true"]
[property name="geometry"]
[rect]
[x]9[/x]
[y]9[/y]
[width]357[/width]
[height]16[/height]
[/rect]
[/property]
[property name="sizePolicy"]
[sizepolicy hsizetype="Preferred" vsizetype="Fixed"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[property name="minimumSize"]
[size]
[width]0[/width]
[height]10[/height]
[/size]
[/property]
[/widget]
[/widget]
[/widget]
[customwidgets]
[customwidget]
[class]PrjToolBar[/class]
[extends]QWidget[/extends]
[header location="global"]controls/Prjtoolbar.h[/header]
[container]1[/container]
[/customwidget]
[customwidget]
[class]PrjNavigationBar[/class]
[extends]QWidget[/extends]
[header location="global"]controls/Prjnavigationbar.h[/header]
[container]1[/container]
[/customwidget]
[customwidget]
[class]PrjListControl[/class]
[extends]QListWidget[/extends]
[header location="global"]controls/Prjlistcontrol.h[/header]
[/customwidget]
[/customwidgets]
[resources/]
[connections/]
[/ui]
And here you can see the UI-Code with vertical layout around the UI-elements:
[?xml version="1.0" encoding="UTF-8"?]
[ui version="4.0"]
[class]PrjNameMeldung1_5[/class]
[widget class="QMainWindow" name="PrjNameMeldung1_5"]
[property name="geometry"]
[rect]
[x]0[/x]
[y]0[/y]
[width]375[/width]
[height]444[/height]
[/rect]
[/property]
[property name="windowTitle"]
[string]MainWindow[/string]
[/property]
[widget class="QWidget" name="centralwidget"]
[layout class="QVBoxLayout" name="verticalLayout"]
[item]
[widget class="PrjNavigationBar" name="m_groupWindowTitle" native="true"]
[property name="sizePolicy"]
[sizepolicy hsizetype="Preferred" vsizetype="Fixed"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[property name="minimumSize"]
[size]
[width]0[/width]
[height]10[/height]
[/size]
[/property]
[/widget]
[/item]
[item]
[layout class="QGridLayout" name="gridLayout"]
[item row="3" column="0"]
[widget class="PrjListControl" name="listWidget"]
[property name="sizePolicy"]
[sizepolicy hsizetype="Expanding" vsizetype="Expanding"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[/widget]
[/item]
[item row="1" column="0"]
[widget class="QLabel" name="m_editTPAggregat"]
[property name="text"]
[string]TPAggregat[/string]
[/property]
[/widget]
[/item]
[item row="2" column="0"]
[widget class="QLabel" name="m_labelAuswahl"]
[property name="text"]
[string]Baugruppe[/string]
[/property]
[property name="alignment"]
[set]Qt::AlignCenter[/set]
[/property]
[/widget]
[/item]
[item row="0" column="0"]
[widget class="QLabel" name="m_editTP"]
[property name="text"]
[string]TP[/string]
[/property]
[property name="alignment"]
[set]Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop[/set]
[/property]
[/widget]
[/item]
[/layout]
[/item]
[item]
[widget class="PrjToolBar" name="m_groupMenuBar" native="true"]
[property name="sizePolicy"]
[sizepolicy hsizetype="Preferred" vsizetype="Fixed"]
[horstretch]0[/horstretch]
[verstretch]0[/verstretch]
[/sizepolicy]
[/property]
[property name="minimumSize"]
[size]
[width]0[/width]
[height]10[/height]
[/size]
[/property]
[/widget]
[/item]
[/layout]
[/widget]
[/widget]
[customwidgets]
[customwidget]
[class]PrjToolBar[/class]
[extends]QWidget[/extends]
[header location="global"]controls/Prjtoolbar.h[/header]
[container]1[/container]
[/customwidget]
[customwidget]
[class]PrjNavigationBar[/class]
[extends]QWidget[/extends]
[header location="global"]controls/Prjnavigationbar.h[/header]
[container]1[/container]
[/customwidget]
[customwidget]
[class]PrjListControl[/class]
[extends]QListWidget[/extends]
[header location="global"]controls/Prjlistcontrol.h[/header]
[/customwidget]
[/customwidgets]
[resources/]
[connections/]
[/ui]