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. How do I make the scrollbars show of a QScrollArea?

How do I make the scrollbars show of a QScrollArea?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k 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.
  • M Offline
    M Offline
    MathSquare
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        MathSquare
        wrote on last edited by
        #3

        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
        0
        • jazzycamelJ Offline
          jazzycamelJ Offline
          jazzycamel
          wrote on last edited by
          #4

          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
          0

          • Login

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