我有一个QDeclarativeView
我要放在QScrollArea
中,问题是scrollarea不起作用。我设置声明性视图有多大并不重要。我没有得到滚动条它就像它不能告诉视图需要滚动条。如果我没有设置setVerticalScrollBarPolicy(Qt :: ScrollBarAlwaysOn);滚动条不会出现。
父作为centralwidget插入borderlayout - 我使用此布局http://qt-project.org/doc/qt-4.8/layouts-borderlayout.html
myWidgets *editWidget = new myWidgets(pathToExe,viewerMgr, this);
editWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
这是myWidget:
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的可见视图更大。
答案 0 :(得分:1)
我已经解决了这个问题,我创建了一个包含qscrollarea的帮助类,修复方法是更新qscrollarea视口。 这是helpwidget的代码
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();
}