如何让滚动条随着控件更新
我做了个滚动画面,画面里有20个按钮,现在我拖动滚动条按钮跟随着滚动,但是我移动按钮的焦点左边的滚动条并不跟着动,怎么设定一下
QVBoxLayout *scrolllayout = new QVBoxLayout;
scrolllayout->setAlignment(Qt::AlignHCenter);
scrolllayout->setSpacing(0);
scrolllayout->setMargin(0);
QWidget *widget = new QWidget(label);
QStringListIterator list(strlist);
for(int i = 0; i < 20; i++){
QToolButton *button = new QToolButton(widget);
if(list.hasNext()){
button->setText(list.next().toLocal8Bit().constData());
}
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
button->setFixedHeight(30);
scrolllayout->addWidget(button);
}
widget->setLayout(scrolllayout);
widget->setFocusPolicy(Qt::NoFocus);
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
scroll = new QScrollArea(label);
scroll->setWidget(widget);
scroll->setFrameStyle(QFrame::NoFrame);
scroll->setWidgetResizable(true);