2

我有一个QDeclarativeView我想提出QScrollArea的问题是滚动区域不起作用。我设置声明性视图有多大并不重要。我没有得到滚动条,就像它不能告诉视图需要滚动条一样。如果我不设置 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 滚动条不出现。

父级作为中央小部件插入到边框布局中 - 我使用此布局http://qt-project.org/doc/qt-4.8/layouts-borderlayout.html

myWidgets *editWidget = new myWidgets(pathToExe,viewerMgr, this);
editWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

这是我的小部件:

QScrollArea* scroll = new QScrollArea();
    view = new QDeclarativeView(this);
    view->setSource(QUrl::fromLocalFile(path));
    view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

    view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
    scroll->setWidget(view);
    scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    scroll->setWidgetResizable(true);

我在内容上尝试了不同的大小,但就像 qscrollview 没有检测到我的小部件何时大于 qscrollarea 的可见视图。

4

1 回答 1

1

我已经解决了这个问题,我创建了一个包含 qscrollarea 的帮助类,修复方法是更新 qscrollarea 视口。这是帮助小部件的代码

testHelpWidget::testHelpWidget(QString path,viewerManager *cMgr, QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
scroll = new QScrollArea(this);

testWidget = new testWidgets(path,cMgr,this);
testWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QObject::connect(testWidget,SIGNAL(zoomChanged()),this,SLOT(repaintZoom()));
scroll->setWidget(qmlWidget);
scroll->setWidgetResizable(true);
scroll->setAlignment(Qt::AlignLeft);
layout->addWidget(scroll);
setLayout(layout);
}

void testHelpWidget::repaintZoom(){
scroll->viewport()->updateGeometry();
scroll->viewport()->update();
scroll->update();
}

testWidget 中缩放功能的代码

void testWidgets::zoom(double scale){
double tmp = scale/1;
double reset = 1/previousScale;
if(scale == previousScale){
    return;
}

view->scale(reset,reset);
view->resize(view->sizeHint()*reset);

view->scale(tmp,tmp);
previousScale = scale;

view->resize(view->sizeHint()*tmp);
view->updateGeometry();
view->update();
emit zoomChanged();
}
于 2013-10-22T12:58:22.533 回答