Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QScrollarea doesnt work
QtWS25 Last Chance

[Solved] QScrollarea doesnt work

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chaf84
    wrote on last edited by
    #1

    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);@
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      chaf84
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chaf84
        wrote on last edited by
        #3

        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 code

        Scrollarea
        @
        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);
        }
        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chaf84
          wrote on last edited by
          #4

          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();
          

          }
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved