How do I make the scrollbars show of a QScrollArea?



  • 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?



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

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



  • 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]



  • 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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.