水平布局 TpHBoxLayout
2025-07-17
介绍
TpHBoxLayout 类 水平布局管理器 TpHBoxLayout 可以使子组件在水平方向排成一行,它将所有的组件分成一行盒子,然后将每一个组件放入一个盒子中。
使用示例
tpDialog *floatScreenH = new TpDialog();
floatScreenH->setBackGroundColor(_RGBA(255, 255, 255, 200));
floatScreenH->setRect(0, 0, 900, 600);
floatScreenH->setAlpha(128);
floatScreenH->setBeMoved(true);
tpHBoxLayout *hLayout = new TpHBoxLayout();
hLayout->setDirection(tpBoxLayout::RightToLeft);
tpVBoxLayout *sonLayout = new TpVBoxLayout();
sonLayout->setContentsMargins(0, 0, 0, 0);
tpHBoxLayout *son2Layout = new TpHBoxLayout();
son2Layout->setContentsMargins(0, 0, 0, 0);
for (int i = 0; i < 4; ++i)
{
TpButton *testButton = new TpButton("测试按钮" + TpString::number(i));
TpButton *testButton3 = new TpButton("子按钮" + TpString::number(i));
TpButton *testButton4 = new TpButton("二级子按钮" + TpString::number(i));
testButton->setMinimumSize(100, 40);
testButton3->setMinimumSize(100, 40);
testButton4->setMinimumSize(100, 40);
testButton->setBackGroundColor(_RGB(255, 15, 15));
hLayout->addWidget(testButton, i + 1);
sonLayout->addWidget(testButton3, i + 1);
son2Layout->addWidget(testButton4, i + 1);
}
sonLayout->addLayout(son2Layout);
hLayout->addLayout(sonLayout, 3);
hLayout->addSpacer(new TpSpacerItem(100, 20, TpSpacerItem::Expanding, TpSpacerItem::Minimum));
floatScreenH->setLayout(hLayout);
效果演示
