【发布时间】:2020-10-21 22:21:07
【问题描述】:
我有以下布局
我在这里尝试做的是在滚动区域上放置一个自定义小部件(蓝色小部件)。
这是我的大纲:
我想在 home_page 和 scrollArea 之间添加那个蓝色小部件,就轮廓而言,或者换句话说,就 GUI 而言,我想在 ScrollAreaContent 上添加那个按钮,但我不想要在我移动 ScrollAreaContent 时将该按钮从其位置移开。
auto sizeX = 0.25 * w;
auto sizeY = 0.9 * h;
ui->scrollArea->setBaseSize(w,h);
ui->scrollAreaWidgetContents->setBaseSize(w,h);
ui->home_page->layout()->setMargin(0);
ui->home_page->layout()->setContentsMargins(0,0,0,0);
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
ui->scrollAreaWidgetContents->layout()->setMargin(0);
ui->scrollAreaWidgetContents->layout()->setContentsMargins(0,0,0,0);
//This list is going to contain the buttons from scrollAreaWidgetContents
auto buttons = new QList<MenuHomeButton *>();
//...
//ADD buttons
//...
ui->stackedWidget->setCurrentIndex(0);
for (auto button : *buttons) {
ui->scrollAreaWidgetContents->layout()->addWidget(button);
connect(button, SIGNAL(buttonClicked(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
}
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
你们中有人知道我该怎么做吗?
【问题讨论】:
-
也许一种方法是按照 Pablo 的建议。将蓝色小部件设为子部件,并在每次水平滚动时移动/更新其位置。它会给人一种蓝色小部件固定在其位置的错觉。
标签: c++ qt5 qt-designer