[PyQt] Learning Qt5 designer (fwd)
Rich Shepard
rshepard at appl-ecosys.com
Tue Jan 10 22:49:02 GMT 2017
On Tue, 10 Jan 2017, Rich Shepard wrote:
> I think my other problems with adding horizontal spacers and layouts can
> be fixed now that I understand the form layout compared with others.
I wrote too quickly. I've read the layout manager page
<http://doc.qt.io/qt-5/layout.html#layout-examples> and looked at the
examples. The code makes sense but I'm trying to learn to use the designer
so I can more quickly create the UI than by writing it all by hand.
A dialog is created with 10 line edit widgets and their labels (code
attached). When I try to add horizontal spacers designer tells me that the
file will not be saved because I don't have a layout on the dialog.
Adding a grid layout, then trying to place a horizontal spacer between the
left two cells and the right two cells it displays across the entire grid
box (because that is displayed in grey when I move the spacer to the dialog
and I cannot place it where I want) and does not shrink. I know this should
be obvious but I'm not seeing how to use designer to add layouts and spacers
(and how to name text line entry widgets so they can be referenced in
methods).
So, my first question is: What is the order of adding layouts (such as the
grid) and spacers?
Rich
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>586</width>
<height>343</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>230</x>
<y>290</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>90</x>
<y>10</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>6</x>
<y>10</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Last name:</string>
</property>
<property name="buddy">
<cstring>lineEdit</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>340</x>
<y>10</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>260</x>
<y>10</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>First name:</string>
</property>
<property name="buddy">
<cstring>lineEdit_2</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>90</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>50</y>
<width>41</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Title:</string>
</property>
<property name="buddy">
<cstring>lineEdit_3</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>340</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>270</x>
<y>50</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Company:</string>
</property>
<property name="buddy">
<cstring>lineEdit_4</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_5">
<property name="geometry">
<rect>
<x>90</x>
<y>90</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_6">
<property name="geometry">
<rect>
<x>340</x>
<y>90</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>30</x>
<y>90</y>
<width>51</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Office:</string>
</property>
<property name="buddy">
<cstring>lineEdit_5</cstring>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>290</x>
<y>90</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Ext.:</string>
</property>
<property name="buddy">
<cstring>lineEdit_6</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_7">
<property name="geometry">
<rect>
<x>90</x>
<y>130</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_8">
<property name="geometry">
<rect>
<x>340</x>
<y>130</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>30</x>
<y>130</y>
<width>51</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Mobile:</string>
</property>
<property name="buddy">
<cstring>lineEdit_7</cstring>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>300</x>
<y>130</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Fax:</string>
</property>
<property name="buddy">
<cstring>lineEdit_8</cstring>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_9">
<property name="geometry">
<rect>
<x>90</x>
<y>170</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_10">
<property name="geometry">
<rect>
<x>340</x>
<y>170</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>30</x>
<y>170</y>
<width>51</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>E-mail:</string>
</property>
<property name="buddy">
<cstring>lineEdit_9</cstring>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>290</x>
<y>170</y>
<width>41</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Main:</string>
</property>
<property name="buddy">
<cstring>lineEdit_10</cstring>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>240</x>
<y>279</y>
<width>341</width>
<height>51</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
More information about the PyQt
mailing list