水平布局 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);
效果演示
