[Solved] QScrollarea doesnt work
-
wrote on 17 Oct 2013, 12:51 last edited by
Hi
I have a qdeclarative view that I want to put in a QScrollArea the problem is that the scrollarea dosent work. It doesnt matter how big I set the declarative view. I dont get the scrollbar it is like it cant tell that the view need a scrollbar. If i dont set setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); the scrollbar doesnt appear.Parent are inserted in a borderlayout as the centralwidget - I use this layout http://qt-project.org/doc/qt-4.8/layouts-borderlayout.html
@
myWidgets *editWidget = new myWidgets(pathToExe,viewerMgr, this);
editWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@Here is myWidget I have tried differentsizes but I cant get it to work
@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); scroll->setMaximumHeight(800); scroll->setMaximumWidth(1000);@
-
wrote on 22 Oct 2013, 07:33 last edited by
I have found what the problem is, the scrollarea or the content dont have any restriction how big they can be.
If i replace
@
view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
@
to
@
view->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@
The scrollarea work, but the problem is that I cant use my zoom function with this solution.
Are there a way to get maximumsize from the layout? I need the widget to fill centralwidget. -
wrote on 22 Oct 2013, 09:54 last edited by
I got the zoom function to work but the scrollarea dont update. It has the original scroll are so if I zoom with a scale of 2 I can only scroll half the area. I have tried to change range of the qscrollbars but they dont update.
My new codeScrollarea
@
QVBoxLayout *layout = new QVBoxLayout;
scroll = new QScrollArea(this);testWidget = new testWidgets(path,cMgr,this); testWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); scroll->setWidget(testWidget); scroll->setWidgetResizable(true); layout->addWidget(scroll); setLayout(layout);
@
Zoom funtion in testWidget
@
void testWidgets::zoom(double scale){
double tmp = scale/previousScale;
view->scale(tmp,tmp);
previousScale = scale;
view->updateGeometry();
}
@sizeHint in test widget
@
QSize testWidgets::sizeHint() const
{
return QSize(view->sizeHint()*previousScale);
}
@ -
wrote on 22 Oct 2013, 12:54 last edited by
I have solved this problem, I created a help class that holds the qscrollarea and the fix is to update qscrollarea viewport.
here is the code for the 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); //show();
}
void testHelpWidget::repaintZoom(){
scroll->viewport()->updateGeometry();
scroll->viewport()->update();
scroll->update();
}
@
Code for zoom function in 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();
}
@
4/4