Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How do I make the scrollbars show of a QScrollArea?

    General and Desktop
    3
    4
    1579
    Loading More Posts
    • 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.
    • M
      MathSquare last edited by

      How do I make the scrollbars show of a QScrollArea show? I put some QWidgets in the QScrollArea then I resize the QScrollArea though code. Some of the QWidgets in the QScrollArea was hidden and the scrollbars wasn't showing. So how do I make it work right?

      1 Reply Last reply Reply Quote 0
      • B
        b1gsnak3 last edited by

        Set the scrollBarPolicy to allways on and that should do it...

        @
        QScrollArea *area = new QScrollArea();
        area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        @

        1 Reply Last reply Reply Quote 0
        • M
          MathSquare last edited by

          Doesn't work
          [quote author="b1gsnak3" date="1364798621"]Set the scrollBarPolicy to allways on and that should do it...

          @
          QScrollArea *area = new QScrollArea();
          area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
          area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
          @[/quote]

          1 Reply Last reply Reply Quote 0
          • jazzycamel
            jazzycamel last edited by

            In what way "doesn't work"? Without a bit more information or seeing your code its difficult to offer any specific help, but the following is a working example:

            @
            #include <QtGui>

            class Widget : public QWidget {
            public:
            Widget(QWidget *parent=0) : QWidget(parent) {
            QVBoxLayout *l=new QVBoxLayout(this);

                QScrollArea *s=new QScrollArea;
                l->addWidget(s);
            
                QWidget *w=new QWidget(this);
                QVBoxLayout *wl=new QVBoxLayout(w);
            
                for(int i=0; i<10; i++)
                    wl->addWidget(new QLabel(QString("Label %1").arg(i)));
            
                s->setWidget(w);
                setGeometry(100, 100, 100, 100);
            }
            

            };

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            Widget w;
            w.show();

            return a.exec&#40;&#41;;
            

            }
            @

            The window should start off very small with both vertical and horizontal scrollbars visible, when the window is resized they will disappear and appear appropriately. Hope this helps ;o)

            For the avoidance of doubt:

            1. All my code samples (C++ or Python) are tested before posting
            2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
            1 Reply Last reply Reply Quote 0
            • First post
              Last post