Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Restrict horizontal scrolling in QScrollArea
Forum Updated to NodeBB v4.3 + New Features

Restrict horizontal scrolling in QScrollArea

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 5.4k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sinjar
    wrote on last edited by
    #1

    I have a widget that contains a QScrollArea. I have set a custom made widget ItemList that is basically a list of items in a QVBoxLayout
    in mainwidget.cpp
    @
    MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent)
    {
    engine = new Engine(QString("/home/user/MyDocs/"));
    engine->loadIndex();
    results = new QList<IndexItem>();
    w= new SearchWidget();
    w2 = new ItemList();
    area=new QScrollArea();
    area->setWidget(w2);
    layout = new QVBoxLayout(this);
    layout->addWidget(w);
    layout->addWidget(area);
    connect(w,SIGNAL(searchPressed()),this,SLOT(performSearch()));
    connect(w,SIGNAL(filter()),this,SLOT(displayFilterDialog()));
    }
    @

    in itemlist.cpp
    @
    ItemList::ItemList(QWidget *parent) :
    QWidget(parent)
    {

    lay = new QVBoxLayout(this);
    
    //performSearch(QString());
    

    }
    ItemList::ItemList(QList<ItemButton *> l, QWidget *parent):
    QWidget(parent)
    {
    lay=new QVBoxLayout(this);
    addButtons(l);
    }

    void ItemList::addButtons(QList<ItemButton *> l) {
    ItemButton *i;
    foreach(i,l) {
    lay->addWidget(i);
    }
    }
    @

    On deploying on an N900 running Maemo5-fremantle everything is fine except that the scroll area scrolls in the horizontal direction also when i flick it.. I do not want it to flick in the horizontal direction.. Can anyone tell me how this can be done.. I dont see any attribute of QScrollArea that disables horizontal scrolling...
    I have also defined sizeHint() for each of the ItemButton as follows:
    @
    QSize ItemButton::sizeHint() const {
    return(QSize(780,100));
    }
    @
    which I believe is well within the horizontal limits of the screen
    PLEASE HELP!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      favoritas37
      wrote on last edited by
      #2

      The property you are looking for is in "QAbstractScrollArea":http://developer.qt.nokia.com/doc/qt-4.8/qabstractscrollarea.html#horizontalScrollBarPolicy-prop, the parent class of QScrollArea. Always look at the inherited members as well.

      So, the property is called horizontalScrollBarPolicy and can be set by the function:
      @
      area=new QScrollArea();
      area->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sinjar
        wrote on last edited by
        #3

        [quote author="favoritas37" date="1326040653"]The property you are looking for is in "QAbstractScrollArea":http://developer.qt.nokia.com/doc/qt-4.8/qabstractscrollarea.html#horizontalScrollBarPolicy-prop, the parent class of QScrollArea. Always look at the inherited members as well.

        So, the property is called horizontalScrollBarPolicy and can be set by the function:
        @
        area=new QScrollArea();
        area->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
        @
        [/quote]

        I know about horizontalScrollBarPolicy and all it does is make the scroll bar disappear
        What I need is that horizontal scrolling * should not take place * even if I flick the screen horizontally....

        1 Reply Last reply
        0
        • F Offline
          F Offline
          favoritas37
          wrote on last edited by
          #4

          In the constructor of both MainWidget and ItemList, as it seems from your code, you haven't assigned the QVBoxLayout to the parent widget. After creating and initializing a layout you have to add it to the widget you want it to exist through setLayout(layout) function. So you code would be like this:

          MainWidget.cpp
          @
          MainWidget::MainWidget(QWidget *parent) :
          QWidget(parent)
          {
          engine = new Engine(QString("/home/user/MyDocs/"));
          engine->loadIndex();
          results = new QList<IndexItem>();
          w= new SearchWidget();
          w2 = new ItemList();
          area=new QScrollArea();
          area->setWidget(w2);
          layout = new QVBoxLayout(this);
          layout->addWidget(w);
          layout->addWidget(area);
          setLayout(layout);
          connect(w,SIGNAL(searchPressed()),this,SLOT(performSearch()));
          connect(w,SIGNAL(filter()),this,SLOT(displayFilterDialog()));
          }
          @

          and itemlist.cpp
          @
          ItemList::ItemList(QWidget *parent) :
          QWidget(parent)
          {

          lay = new QVBoxLayout(this);
          setLayout(lay);
          //performSearch(QString());
          

          }
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sinjar
            wrote on last edited by
            #5

            That doesnt work either
            Either we pass the widget to the layout's constructor OR we use setLayout() to parent the layout.
            It says so in the documentation of setLayout()
            If it were not so I would not have been getting the list of ItemButtons arranged vertically when I call ItemList::addButtons() which I sure am
            and...
            I am still able to flick horizontally... :(

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sinjar
              wrote on last edited by
              #6

              The same also happens when I use a @QListWidget@ and add items to it...
              When I flick horizontally it moves and then springs back to its initial position...
              ;(

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bhupal
                wrote on last edited by
                #7
                area=new QScrollArea();
                area->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
                

                This worked for me - Thanks a lot

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sinjar
                  wrote on last edited by
                  #8

                  [quote author="Bhupal" date="1339560007"] area=new QScrollArea();
                  area->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );

                  This worked for me - Thanks a lot[/quote]

                  Tried that already... It only hides the scrollbar, doesnt prevent the scrolling ..

                  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