Qt布局

Qt的基本布局

  • QLayout
    • QBoxLayout
      • QHBoxLayout
      • QVBoxLayout
    • QGridLayout

布局中常用的方法

  1. addWidget 向布局中添加需要布局的控件
  2. addLayout 向布局中添加需要布局的子布局
void addWidget(
 QWidget *widget,//需要插入的控件对象
 int fromRow, //插入的行列
 int fromColumn,
 int rowSpan, //占用的行数,列数
 int columnSpan, 
 Qt::Alignment alignment = Qt::Alignment()//描述控件的对齐方式
 )
This is an overloaded function.
This version adds the given widget to the cell grid, spanning multiple rows/columns. 
The cell will start at fromRow, fromColumn spanning rowSpan rows and columnSpan columns.
The widget will have the given alignment.
If rowSpan and/or columnSpan is -1, then the widget will extend to the bottom and/or right edge, respectively.
void addLayout(
QLayout *layout,
 int row, 
 int column, 
 int rowSpan,
 int columnSpan,
 Qt::Alignment alignment = Qt::Alignment())
This is an overloaded function.
This version adds the layout layout to the cell grid, spanning multiple rows/columns.
 The cell will start at row, column spanning rowSpan rows and columnSpan columns.
If rowSpan and/or columnSpan is -1, then the layout will extend to the bottom and/or right edge, respectively.
     //hostLabel放在第一行第一列
    Layout->addWidget(hostLabel,0,0); 

    //LineEditLocalHostName放在第一行第二列
    Layout->addWidget(LineEditLocalHostName,0,1);

    //Btndetail放在第三行第一列,占据一行两列
    Layout->addWidget(Btndetail,2,0,1,2);

设置控件缩放因子

每个布局都有相应的拉伸因子设置函数。下面是QGridLayout里面的设置函数:

void setColumnStretch ( int column, int stretch );

void setRowStretch ( int row, int stretch );

具体使用如下

Layout->setColumnStretch(0,1);

Layout->setColumnStretch(1,3);

这样在窗体反正改变的时候,hostLabel与LineEditLocalHostName会按1:3的比例发生改变。

并且,在不进行其他尺寸设置的时候(最大值最小值固定什么的),控件也会以这个比例显示在界面上。

NetworkInfo

附github:QT获取本机网络信息的demo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Erice_s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值