【发布时间】:2019-03-01 21:26:15
【问题描述】:
我正在尝试添加一个带有可滚动布局的框(位置:1140、485 和大小:225、365),布局内带有按钮。我不希望框移动/调整大小。我希望盒子有一个滚动条,我们可以通过它滚动浏览其中的所有按钮。
到目前为止,我的代码根本不起作用,我得到的只是一个充满按钮的布局,带有一个拉伸框(我不想要)。到目前为止唯一有效的是按钮以正确的方式添加到框中。
我所需要的只是使框可滚动并使其在按钮过多时不会自行调整大小。
这是我的代码:
QWidget *box = new QWidget(); //creating the box and placing it where I want it
box->move(1145, 485);
box->resize(225, 365);
gameScene->addWidget(box); //adding it to the main scene
//where AM i supposed to use this?
QScrollArea *scrollArea = new QScrollArea();
QGridLayout *layout = new QGridLayout();
box->setLayout(layout);
//testButtons
QPushButton *testButton1 = new QPushButton("Button1");
layout->addWidget(testButton1);
....
QPushButton *testButtonN = new QPushButton("ButtonN");
layout->addWidget(testButtonN);
您可以在右下角看到标题为 GAME TRANSCRIPT 的框。 我只想让盒子像它一样包含按钮。但我不希望它调整大小,我希望它可以滚动,因为它会切断底部的按钮。
【问题讨论】: