日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【转】QGridLayout 详解

發(fā)布時(shí)間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】QGridLayout 详解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自:https://blog.csdn.net/u013928315/article/details/78123573

一、QGridLayout屬性介紹

?

1、QGridlayout以方格的形式管理窗口部件,先看QGridLayout的屬性,如下圖

2、各個(gè)參數(shù)的介紹

layoutLeftMargin ...至layoutBottomMargin在ui_MainWindow.h中自動(dòng)生成的代碼是:

gridLayout->setContentsMargins(20, 10, 10, 10);

學(xué)過CSS都知道,這是設(shè)置一個(gè)元素所有外邊距的寬度,或者設(shè)置各邊上外邊距的寬度

On most platforms, the margin is 11 pixels in all directions.

?

HorizontalSpacing...至VerticalSpacing在ui_MainWindow.h中自動(dòng)生成的代碼是:

?

? ? ? ? gridLayout->setHorizontalSpacing(6);

? ? ? ? gridLayout->setVerticalSpacing(6);

? ? ? ? 這是設(shè)置兩個(gè)控件之間的水平和豎直距離

?

LayoutRowStretch在ui_MainWindow.h中自動(dòng)生成的代碼是:

?

gridLayout->setRowStretch(0, 1);

? ? ? ? gridLayout->setRowStretch(1, 1);

? ? ? ? gridLayout->setRowStretch(2, 1);

表示在第0行、第1行、第2行 在豎直方向的空間比例分配,大家稍微改一下參數(shù)就能看出來效果

LayoutColumnStretch在ui_MainWindow.h中自動(dòng)生成的代碼是:? ? ??

gridLayout->setColumnStretch(1, 1);

?

表示設(shè)置第0列、第1列兩者在水平方向的空間比例分配。

?

?

LayoutRowMinimumHeight在ui_MainWindow.h中自動(dòng)生成的代碼是:

?

? ? ? ? gridLayout->setRowMinimumHeight(0, 1);

? ? ? ? gridLayout->setRowMinimumHeight(1, 2);

? ? ? ? gridLayout->setRowMinimumHeight(2, 3);

表示在第0行、第1行、第2行的最小高度是1pixels,2pixels,3pixels

LayoutColumnMinimumWidth在ui_MainWindow.h中自動(dòng)生成的代碼是:

?

? gridLayout->setColumnMinimumWidth(0, 4);

? ? ? ? gridLayout->setColumnMinimumWidth(1, 5);

表示設(shè)置第0列、第1列的最小寬度是4pixels、5pixels

?

?

LayoutSizeConstraint在ui_MainWindow.h中自動(dòng)生成的代碼是:

gridLayout->setSizeConstraint(QLayout::SetDefaultConstraint);

?

This property holds the resize mode of the layout.看下表

?

?

?

?

enum QLayout::SizeConstraint

The possible values are:

Constant Value Description

QLayout::SetDefaultConstraint0The main widget's minimum size is set to?minimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize3The main widget's size is set to?sizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize2The main widget's minimum size is set to?minimumSize(); it cannot be smaller.
QLayout::SetMaximumSize4The main widget's maximum size is set to?maximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize5The main widget's minimum size is set to?minimumSize() and its maximum size is set tomaximumSize().
QLayout::SetNoConstraint1

The widget is not constrained.

?

?

?

QFormLayout屬性介紹

1、QFormLayout類管理輸入型控件和它的label組成的那些form表格,包括它的界面參數(shù)如下圖

?

?

2、界面中對(duì)應(yīng)的代碼如下表,

?

?

Cpp代碼???

  • formLayout?=?new?QFormLayout(widget1);??
  • ????????formLayout->setSpacing(6);??
  • ????????formLayout->setContentsMargins(11,?11,?11,?11);??
  • ????????formLayout->setObjectName(QString::fromUtf8("formLayout"));??
  • ????????formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);??
  • ????????formLayout->setRowWrapPolicy(QFormLayout::DontWrapRows);??
  • ????????formLayout->setContentsMargins(0,?0,?0,?0);??
  • ????????label_4?=?new?QLabel(widget1);??
  • ????????label_4->setObjectName(QString::fromUtf8("label_4"));??
  • ??
  • ????????formLayout->setWidget(0,?QFormLayout::LabelRole,?label_4);??
  • ??
  • ????????lineEdit?=?new?QLineEdit(widget1);??
  • ????????lineEdit->setObjectName(QString::fromUtf8("lineEdit"));??
  • ??
  • ????????formLayout->setWidget(0,?QFormLayout::FieldRole,?lineEdit);??
  • ??
  • ????????label_5?=?new?QLabel(widget1);??
  • ????????label_5->setObjectName(QString::fromUtf8("label_5"));??
  • ??
  • ????????formLayout->setWidget(1,?QFormLayout::LabelRole,?label_5);??
  • ??
  • ????????comboBox?=?new?QComboBox(widget1);??
  • ????????comboBox->setObjectName(QString::fromUtf8("comboBox"));??
  • ??
  • ????????formLayout->setWidget(1,?QFormLayout::FieldRole,?comboBox);??
  • ?

    3、其中值得一說的是:LayoutFieldGrowthPolicy屬性

    ?

    ?

    enum QFormLayout::FieldGrowthPolicy

    This enum specifies the different policies that can be used to control the way in which the form's fields grow.

    Constant Value Description

    QFormLayout::FieldsStayAtSizeHint0The fields never grow beyond their?effective size hint. This is the default forQMacStyle.
    QFormLayout::ExpandingFieldsGrow1Fields with an horizontal?size policy?of?Expanding?or?MinimumExpanding?will grow to fill the available space. The other fields will not grow beyond their effective size hint. This is the default policy for Plastique.
    QFormLayout::AllNonFixedFieldsGrow2All fields with a size policy that allows them to grow will grow to fill the available space. This is the default policy for most styles.

    ?

    ?

    ?

    4、還有一個(gè)屬性值得說:LayoutRowWrapPolicy

    ?

    This property holds the way in which the form's rows wrap.

    //這個(gè)屬性設(shè)置了表格如何排版各個(gè)元素

    If you want to display each label above its associated field (instead of next to it), set this property to WrapAllRows.

    //如果你想把每個(gè)標(biāo)簽放在相關(guān)字段的上方,而不是和它相鄰,就設(shè)置這個(gè)屬性值為WrapAllRows。

    ?

    ?

    enum QFormLayout::RowWrapPolicy

    This enum specifies the different policies that can be used to control the way in which the form's rows wrap.

    Constant Value Description

    QFormLayout::DontWrapRows0Fields are always laid out next to their label. This is the default policy for all styles except Qt Extended styles and?QS60Style.
    QFormLayout::WrapLongRows1Labels are given enough horizontal space to fit the widest label, and the rest of the space is given to the fields. If the minimum size of a field pair is wider than the available space, the field is wrapped to the next line. This is the default policy for Qt Extended styles and andQS60Style.
    QFormLayout::WrapAllRows2Fields are always laid out below their label.

    總結(jié)

    以上是生活随笔為你收集整理的【转】QGridLayout 详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。