当前位置: 代码迷 >> QT开发 >> 怎么让滚动条随着控件更新
  详细解决方案

怎么让滚动条随着控件更新

热度:7   发布时间:2016-04-25 04:03:35.0
如何让滚动条随着控件更新
我做了个滚动画面,画面里有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);

------解决方案--------------------
用QListWidget不是更方便吗。
  相关解决方案