Why does Qt Designer add so much space? - c++

Why does Qt make so much space? How can I fix this? I just want to create two labels, two text boxes and a login button. I'm trying to make a login form.
Something like this:
Why does it need so much space to just have small buttons?
This is the nicest I've been able to get it to look, but even this looks terrible.

Just add a Vertical Spacer to the top and the bottom, then you will have your expected result.
If you would like to add it through the code and not in Designer, you would need to add it on the QLayout with QBoxLayout::addStretch(int stretch = 0) or QBoxLayout::addSpacing(int size), depending on your need

Do you want something like that? example
You can use spacers from Qt Designer to achieve what you want, I guess.
Below is the UI code of my example:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>408</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>GroupBox</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit" />
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_2" />
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar" />
</widget>
<resources />
<connections />
</ui>
Moreover, a quick tip for you, if you are a beginner, I consider this as a mistake to use two layouts when you do not need two of them: in your example, remove the "formLayout" and format your "LoginScreen" as a QFormLayout instead.

Related

how to center a middle widget and expand its cell

In Qt designer, how do i center a middle widget in a vertical/horizontal/grid layout and expand its cell at the same time, what i want to get is something like this:
what i get:
One possible solution is to place the middle QPushButton in a QWidget through a layout, and then place that QWidget in the second column of the QHBoxLayout:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Output:
You're gonna need to add a horizontal spacer. And then for the spacer you can add properties. Whether it should be fixed or expanding.
So first select and add a horizontal spacer, and then when you select the horizontal spacer, in the properties widget you'll be able to set properties to it:
The way the spacer will be placed in-between two widgets, is by first dragging the spacer and placing it in between the widgets, selecting all of them and then right-click and group horizontally. This will put your widgets and the spacer in a horizontal layout:
If you want to do it in the code manually, look into QSpacerItem.

Set positions of different widgets, buttons, etc and create lineedit with horizontal scrollbar

In the window below you can see how my ui looks so far.
Now I have the following two problems:
I want that the right half of the window has a (almost) fixed size when in- or decreasing the window in size. The left part (the big square with the scrollbars) should fill the rest of the window. It doesn't have to be a square. It should occupy all the rectangular space that's left. When decreasing the window in size, the right half could also become a bit smaller, but I want to set a minimum to that, so the buttons aren't ridiculously small. Vice versa when increasing the window in size.
EDIT
And how do I set the "origin point" of e.g. the right halt to the top right corner? So if I enlarge the window to the right the right half sticks to the right side and makes space for the white rectangle so spread.
When I decrease the windows size:
When I increase the windows size:
EDIT END
And I'd like to have a QLineEdit, can be any text line format as long as it looks like a single line, with a horizontal scrollbar beneath Dropdown, where it reads Textfeld. The way it is below, is just a simple QLineEdit with a horizontal QScrollBar beneath it, but they are still seperate and do not interact with each other.
I've looked on stackoverflow and on other websites, but I've never found a solution for any of those :/
If I try to but QLineEdit inside QScrollArea it looks like this and doesn't work:
That's the associated .ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>patchbot_game</class>
<widget class="QMainWindow" name="patchbot_game">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>779</width>
<height>717</height>
</rect>
</property>
<property name="windowTitle">
<string>patchbot_game</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QScrollBar" name="verticalScrollBar_2">
<property name="geometry">
<rect>
<x>351</x>
<y>59</y>
<width>16</width>
<height>491</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QPushButton" name="selectNewColonyButton">
<property name="geometry">
<rect>
<x>610</x>
<y>6</y>
<width>150</width>
<height>50</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Andere Kolonie ...</string>
</property>
</widget>
<widget class="QScrollBar" name="horizontalScrollBar_2">
<property name="geometry">
<rect>
<x>20</x>
<y>550</y>
<width>331</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="currentColonyLabel">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>341</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Aktuelle Kolonie: Lithium-Stollen 13-A</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>610</x>
<y>190</y>
<width>130</width>
<height>73</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>9</number>
</property>
<property name="midLineWidth">
<number>10</number>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>130</width>
<height>59</height>
</rect>
</property>
<widget class="QLineEdit" name="botCommandEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>130</width>
<height>50</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string><html><head/><body><p><br/></p></body></html></string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string>1234567890987654323456789</string>
</property>
<property name="maxLength">
<number>32762</number>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
<property name="cursorPosition">
<number>25</number>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="dragEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Textfeld</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>420</x>
<y>310</y>
<width>311</width>
<height>201</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="horizontalSpacing">
<number>20</number>
</property>
<property name="verticalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>15</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>15</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="startButton">
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="singleStepButton">
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Einzelschritt</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="autoButton">
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Automatik</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pauseButton">
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Anhalten</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="abortButton">
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Abbruch</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QComboBox" name="repeatDropdown">
<property name="geometry">
<rect>
<x>610</x>
<y>100</y>
<width>130</width>
<height>50</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentText">
<string>1</string>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<property name="frame">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
<widget class="QWidget" name="layoutWidget_2">
<property name="geometry">
<rect>
<x>420</x>
<y>100</y>
<width>164</width>
<height>164</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="upButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_oben.tga</normaloff>:/grafics/grafics/pfeile/pfeil_oben.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="deleteButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string><</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="leftButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_links.tga</normaloff>:/grafics/grafics/pfeile/pfeil_links.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="waitButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>W</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="rightButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_rechts.tga</normaloff>:/grafics/grafics/pfeile/pfeil_rechts.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="downButton">
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_unten.tga</normaloff>:/grafics/grafics/pfeile/pfeil_unten.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>331</width>
<height>491</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Umgebungskarte</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>510</x>
<y>270</y>
<width>131</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Missionsablauf</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>530</x>
<y>50</y>
<width>131</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Programmieren</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>779</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources>
<include location="grafics.qrc"/>
</resources>
<connections/>
</ui>
Help would be appreciated and if futher information is required, I'd be happy to help.

how to convert .ui fully into c++ header and source file

I created something with the Qt Creator Design-Tool.
By doing so I endet up with a .ui, a .h and two .cpp (mainwindow.cpp and main.cpp) files containing the following:
mainwindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>819</width>
<height>634</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>580</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout" rowstretch="1,4,4,0" columnstretch="2,0" rowminimumheight="1,1,10,1" columnminimumwidth="1,1">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="1">
<widget class="QFrame" name="selectColonyFrame">
<property name="minimumSize">
<size>
<width>150</width>
<height>40</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QPushButton" name="selectColonyButton">
<property name="geometry">
<rect>
<x>80</x>
<y>0</y>
<width>150</width>
<height>40</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Andere Kolonie ...</string>
</property>
</widget>
</widget>
</item>
<item row="0" column="0">
<widget class="QFrame" name="currentColonyFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QLabel" name="currentColonyLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>301</width>
<height>16</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>15</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>460</width>
<height>25</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Aktuelle Kolonie: Lithium-Stollen 13-A</string>
</property>
</widget>
</widget>
</item>
<item row="3" column="1">
<widget class="QFrame" name="missionControlsFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>8</horstretch>
<verstretch>8</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>180</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="misisonControlsLabel">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Missionsablauf</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="missionControlsGridLayout">
<property name="leftMargin">
<number>15</number>
</property>
<property name="topMargin">
<number>20</number>
</property>
<property name="rightMargin">
<number>15</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>20</number>
</property>
<property name="verticalSpacing">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="startButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="abortButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Abbruch</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="singleStepButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Einzelschritt</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="autoButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Automatik</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pauseButton">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Anhalten</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" rowspan="2">
<widget class="QFrame" name="botControlsFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>4</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>160</width>
<height>120</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>320</width>
<height>240</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2" rowstretch="0,2,1,1">
<item row="1" column="0" rowspan="3">
<layout class="QGridLayout" name="botControlsGridLayout" rowstretch="0,0,0" columnstretch="0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="2" column="1">
<widget class="QPushButton" name="downButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_unten.tga</normaloff>:/grafics/grafics/pfeile/pfeil_unten.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="upButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_oben.tga</normaloff>:/grafics/grafics/pfeile/pfeil_oben.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="waitButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
<pointsize>15</pointsize>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="text">
<string>W</string>
</property>
<property name="icon">
<iconset theme="&#9664">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="leftButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_links.tga</normaloff>:/grafics/grafics/pfeile/pfeil_links.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="deleteButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string><</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="rightButton">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="grafics.qrc">
<normaloff>:/grafics/grafics/pfeile/pfeil_rechts.tga</normaloff>:/grafics/grafics/pfeile/pfeil_rechts.tga</iconset>
</property>
<property name="iconSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="botControlsLabel">
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Programmieren</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="repeatDropdown">
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="currentText">
<string>1</string>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<property name="frame">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QFrame" name="frame_6">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QFrame" name="botCommandFrame">
<property name="minimumSize">
<size>
<width>100</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QTextEdit" name="botCommandTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>16</y>
<width>108</width>
<height>50</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>130</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Textfeld</string>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" rowspan="3">
<widget class="QFrame" name="mapFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>120</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Umgebungskarte</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QScrollBar" name="verticalScrollBar">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QScrollBar" name="horizontalScrollBar">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>819</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources>
<include location="grafics.qrc"/>
</resources>
<connections/>
</ui>
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_upButton_clicked();
void on_rightButton_clicked();
void on_downButton_clicked();
void on_leftButton_clicked();
void on_waitButton_clicked();
void on_deleteButton_clicked();
void on_selectColonyButton_clicked();
void on_startButton_clicked();
void on_abortButton_clicked();
void on_singleStepButton_clicked();
void on_autoButton_clicked();
void on_pauseButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QMessageBox"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_upButton_clicked()
{
QMessageBox::information(this, "button", "up");
}
void MainWindow::on_rightButton_clicked()
{
QMessageBox::information(this, "button", "right");
}
void MainWindow::on_downButton_clicked()
{
QMessageBox::information(this, "button", "down");
}
void MainWindow::on_leftButton_clicked()
{
QMessageBox::information(this, "button", "left");
}
void MainWindow::on_waitButton_clicked()
{
QMessageBox::information(this, "button", "wait");
}
void MainWindow::on_deleteButton_clicked()
{
QMessageBox::information(this, "button", "delete");
}
void MainWindow::on_selectColonyButton_clicked()
{
QMessageBox::information(this, "button", ui->selectColonyButton->text());
}
void MainWindow::on_startButton_clicked()
{
QMessageBox::information(this, "button", ui->startButton->text());
}
void MainWindow::on_abortButton_clicked()
{
QMessageBox::information(this, "button", ui->abortButton->text());
}
void MainWindow::on_singleStepButton_clicked()
{
QMessageBox::information(this, "button", ui->singleStepButton->text());
}
void MainWindow::on_autoButton_clicked()
{
QMessageBox::information(this, "button", ui->autoButton->text());
}
void MainWindow::on_pauseButton_clicked()
{
QMessageBox::information(this, "button", ui->pauseButton->text());
}
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}
Now I what I'd like to have is a .cpp file containing not only the signals and slot I created manually, but everything. Every layout I added with the designer, every label, every button. And as far as I know there is a way to achieve exactly that: qmakeor uic
The problem now is: how do I actually use one of those?
I've tried using uic via command prompt by opening the folder all those files are in and executing this: uic -o mainwindow.h mainwindow.ui
(googled a bit and found that)
But the error I got was something like this: either the "uic" command written wrongly or couldn't be found. (tried to translate it from my language)
Any ideas on how to fix the problem or any different ideas on how to achieve what I need?
Use qmake, here's the link with all basic explanations:
https://doc.qt.io/qt-5/qmake-tutorial.html
For .ui files, you add them to the .pro file like this:
FORMS += foo.ui

Qt bug where container resize at run time

I have a nasty bug where the size of my container(s) / layout(s) resize themselves whenever I click on a text box. When the resize occurs, all of the widgets are re-aligned to what they should be in the designer (I created the layout and the interface using the designer). I thought that if I were to force the interface to redraw itself when displayed, the containers would resize but this did not work. I have been looking on the net to see if there is anything similar and so far, there is nothing. I have pictures and a minimal-ish code example prepared.
I am running linux mint 19.1 with Qt 5.9 (the version that comes with my distro).
Any help will be greatly appreciated.
Thank you.
Before the resize:
After the resize:
Also, here is the code example. I apologize for the length of this one but this is literally the smallest that I could get:
mainwindow.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>709</height>
</rect>
</property>
<property name="font">
<font>
<family>DejaVu Sans Mono</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>431</width>
<height>621</height>
</rect>
</property>
<property name="font">
<font>
<family>DejaVu Sans Mono</family>
</font>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_9">
<attribute name="title">
<string>Access Control</string>
</attribute>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>401</width>
<height>561</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_7">
<attribute name="title">
<string>Misc. Options</string>
</attribute>
<widget class="QScrollArea" name="scrollArea_5">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>400</width>
<height>571</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_5">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>444</width>
<height>608</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QVBoxLayout" name="verticalLayout_12">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLabel" name="label_241">
<property name="maximumSize">
<size>
<width>443</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>BEEPER OPTIONS</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_262">
<property name="minimumSize">
<size>
<width>341</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>This is a checkbox that is being used to </string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_13">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLabel" name="label_242">
<property name="maximumSize">
<size>
<width>443</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>DRYCYCLE CONTROLS</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_273">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_274">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_11">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_14">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLabel" name="label_243">
<property name="maximumSize">
<size>
<width>443</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Operation Bypass Controls</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_275">
<property name="minimumSize">
<size>
<width>341</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_276">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_277">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_278">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_279">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>443</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Option</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="simulateSortingCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Another text that is really long in order</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="randomSortCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Sub option 1</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="sequentialSortCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>34</height>
</size>
</property>
<property name="text">
<string>Sub option 2</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="fixedSortCheckBox">
<property name="text">
<string>Sub option 3</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="Fixed_Sort_to_bin">
<property name="text">
<string>8</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>110</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QWidget>
#include <QFont>
#define SELECTED_CHECK_BOX "QCheckBox {border: 2px solid gray;}"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QWidget *p_previouseSelectedWidget = nullptr;
QFont p_setFont;
public slots:
void handleFocusChange(QWidget *oldWidget, QWidget *newWidget);
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
p_setFont = this->font();
connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(handleFocusChange(QWidget*,QWidget*)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::handleFocusChange(QWidget *oldWidget, QWidget *newWidget)
{
if(!this->isHidden())
{
if(!dynamic_cast<QPushButton*>(newWidget))
{
if(p_previouseSelectedWidget)
{
p_previouseSelectedWidget->setStyleSheet("");
p_previouseSelectedWidget->setFont(p_setFont);
}
p_previouseSelectedWidget = newWidget;
}
if(dynamic_cast<QCheckBox*>(newWidget))
{
// Do some stuff
newWidget->setStyleSheet(SELECTED_CHECK_BOX);
}
}
}
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Edit:
I am now sharing the mainWindow.ui.
I have solved the issue. Basically, in the scrollAreaWidgetContents container, I changed the layoutSizeContraint from the default value to SetMinandMaxSize.
I have tried this on a number of my forms and the window is not longer displaying the behaviour posted above.

How to disable word wrapping on QWebView?

I'm using what I believe is a pretty standard example of a WYSIWYG editor from graphics-dojo built using a QWebView. The source can be found here
I'm trying to disable the word wrapping in the QWebView so if an element extends beyond the width of the window, a horizontal scrollbar will appear and no wrapping will occur. By default it appears that the text in the QWebView wraps at all window widths except when the width is resized to under about 100 pixels which is when the horizontal scrollbar appears. Given this behavior I know the horizontal scrollbar is enabled. I've looked at QWebView, QWebFrame, and QWebPage and can't seem to find any references to word wrapping. I wonder if it is a property of the underlying WebKit.
In summary: How can I disable word wrapping on a QWebView so that a horizontal scrollbar appearing is the default behavior?
The QWebView is contained in the htmleditor.ui file like this.
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>659</width>
<height>398</height>
</rect>
</property>
<property name="windowTitle">
<string>HTML Editor</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
...