[PyQt] Learning Qt5 designer (fwd)

Hans-Peter Jansen hpj at urpla.net
Thu Jan 12 15:15:53 GMT 2017


On Dienstag, 10. Januar 2017 14:49:02 Rich Shepard wrote:
> 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,

sorry, saw this only after responding to the other thread..

Starting from the attached ui, the vertical layout around the buttons don't make much 
sense, select and delete it. 

Now select all labels and edits (by wire frame or control click), and click on grid layout in 
tool bar:



Next, click into background and on vertical layout in tool bar:



That's it, you have a layouted dialog, that resizes correctly:



Next, you should give your line edits better names (select and edit in property editor:



and add ampersands to the labels:



The buddy editor links the labels with the edits. 
Next tab order, and you're done.

Any special signals and slots can go into the constructor of your widget.

Pete



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bild
Type: image/png
Size: 12474 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bild1
Type: image/png
Size: 17382 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bild2
Type: image/png
Size: 15534 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bild3
Type: image/png
Size: 23651 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bild4
Type: image/png
Size: 18716 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: contactsdlg.ui
Type: application/x-designer
Size: 5204 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/c3075ddd/attachment-0001.bin>


More information about the PyQt mailing list