Layout manager,

Source: Internet
Author: User

Layout manager,
1. How to implement the following user interface

1.1,Solution

1.1.1,Absolute positioning component coordinates and sizes

1.1.2,Nested QBoxLayout (three horizontal layout and one vertical layout)

1.1.3,Create QGridLayout 3x2

// First, use GridLayout to implement the above Layout

. Cpp File

# Include "widget. h"

# Include

# Include

# Include

Widget: Widget (QWidget * parent)

: QWidget (parent)

{

QLabel * Name_Label = new QLabel ("Name :");

QLabel * Email_Label = new QLabel ("Email :");

QLabel * Address_Label = new QLabel ("Address :");

QLineEdit * Name_edit = new QLineEdit ();

QLineEdit * Email_edit = new QLineEdit ();

QLineEdit * Address_edit = new QLineEdit ();

QGridLayout * gridlayout = new QGridLayout ();

Gridlayout-> setSpacing (10); // The interval of each control in the layout is 10.

Gridlayout-> addWidget (Name_Label, 0, 0); // the control is in the 0 column of The 0th rows.

Gridlayout-> addWidget (Email_Label, 1, 0 );

Gridlayout-> addWidget (Address_Label, 2, 0 );

Gridlayout-> addWidget (Name_edit, 0, 1); // use this grid layout to split the interface into three rows and two columns.

Gridlayout-> addWidget (Email_edit, 1, 1 );

Gridlayout-> addWidget (Address_edit, 2, 1 );

// Gridlayout-> setColumnStretch (0, 1); // The ratio of 0th columns to 1st columns is.

// Gridlayout-> setColumnStretch (1, 4 );

This-> setLayout (gridlayout );

This-> setWindowTitle ("FTP ");

}

Widget ::~ Widget ()

{

}

2. QFormLayout layout manager

2.1,ToFormManagement interface components

2.2,In the form layoutLabels and componentsYesMutual correspondenceRelationship

2.3,QFormLayout usage Overview

2.4,Style functions of QFormLayout

2.5,Form LayoutSupport nesting,Other layout managersIt can be managed as a sub-Layout

. Cpp implementation file.

# Include "widget. h"

# Include

# Include

# Include

Widget: Widget (QWidget * parent)

: QWidget (parent, Qt: WindowCloseButtonHint)

{

QLineEdit * Name_edit = new QLineEdit ();

QLineEdit * Email_edit = new QLineEdit ();

QLineEdit * Address_edit = new QLineEdit ();

QFormLayout * formlayout = new QFormLayout ();

Formlayout-> setSpacing (10); // set the component interval in this layout to 10.

Formlayout-> addRow ("Name:", Name_edit); // The first parameter is a text tag, and the second parameter is a component.

Formlayout-> addRow ("Email:", Email_edit); // 2 rows

Formlayout-> addRow ("Address:", Address_edit); // 3 rows

// Formlayout-> setLabelAlignment (Qt: AlignRight); // right alignment of the Label control.

// Formlayout-> setRowWrapPolicy (QFormLayout: WrapAllRows); // set the style. The fields are divided into two rows and placed under the label.

Formlayout-> setRowWrapPolicy (QFormLayout: WrapLongRows );

This-> setLayout (formlayout );

This-> setWindowTitle ("FTP ");

}

Widget ::~ Widget ()

{

}

3. Summary

3.1,QFormLayoutIn formManagement interface components

3.2,QFormLayout'sSimple and clear style settings

3.3,QFormLayoutSupport nesting layout manager

3.4,QFormLayout isEmbedded productsThe most common layout method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.